newbie needing help

R

raecer

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 :)
 
V

Victor Bazarov

raecer said:
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
 
R

Ron Natalie

raecer said:
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());
 
P

Phlip

raecer said:
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());
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,756
Messages
2,569,540
Members
45,025
Latest member
KetoRushACVFitness

Latest Threads

Top