Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > newbie needing help

Reply
Thread Tools

newbie needing help

 
 
raecer
Guest
Posts: n/a
 
      11-19-2004
I want to use cin to get input from the user, and then use it in the
system command. how can this be done? i was thinking something like
this
int h;
cin >> h;
system = ("echo test h test")
that is, i want the value h to be placed inside the system command.
how can i do this? sorry for the n00b question
 
Reply With Quote
 
 
 
 
Victor Bazarov
Guest
Posts: n/a
 
      11-19-2004
raecer wrote:
> I want to use cin to get input from the user, and then use it in the
> system command. how can this be done? i was thinking something like
> this
> int h;
> cin >> h;
> system = ("echo test h test")
> that is, i want the value h to be placed inside the system command.
> how can i do this? sorry for the n00b question


The usual way is to compose the string you want to use to call 'system'
with in a separate object, then pass its value to 'system':

int h;
cin >> h;
ostringstream os;
os << "echo test " << h << " test";
system(os.str().c_str());

V
 
Reply With Quote
 
 
 
 
Ron Natalie
Guest
Posts: n/a
 
      11-19-2004
raecer wrote:
> I want to use cin to get input from the user, and then use it in the
> system command. how can this be done? i was thinking something like
> this
> int h;
> cin >> h;
> system = ("echo test h test")
> that is, i want the value h to be placed inside the system command.
> how can i do this? sorry for the n00b question


#include <sstream>

ostringstream o ;
o << "echo test " << h << " test";
system(o.str().c_str());
 
Reply With Quote
 
Phlip
Guest
Posts: n/a
 
      11-19-2004
raecer wrote:

> I want to use cin to get input from the user, and then use it in the
> system command. how can this be done? i was thinking something like
> this
> int h;
> cin >> h;
> system = ("echo test h test")
> that is, i want the value h to be placed inside the system command.
> how can i do this? sorry for the n00b question


std::stringstream z;
z << "echo test " << h << " test";
system(z.str().c_str());

--
Phlip
http://industrialxp.org/community/bi...UserInterfaces



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Newbie needing some help with segmentation fault Hendrik Maryns C Programming 20 12-07-2007 02:58 PM
html newbie needing help with simple form slinky HTML 2 05-30-2007 10:48 PM
Newbie needing help with a simple ASP.NET <table> problem...! mj.redfox.mj@gmail.com ASP .Net 4 03-02-2007 02:15 PM
newbie - needing direction bobueland@yahoo.com Python 4 12-05-2005 04:02 PM
XML Newbie needing some serious help.. rh0dium Python 2 05-20-2005 12:20 PM



Advertisments