Using variable in System() function?

Hello

How can I use a variable in the system() function?
Like this:
1
2
3
string a;
cin >> a;
system("ping ", a);

(Just an example).

Of course that code doesn't work, could someone show me an example of how to achieve this?

Thanks for reading,
Niely
Last edited on
1
2
3
4
    string a;
    cin >> a;
    string b = "ping " + a;
    system(b.c_str());
1
2
3
4
5
6
7
8
std::string ip;

cout << "enter an IP address: ";
cin >> ip;

std::string cmd = "ping " + ip;

system( cmd.c_str() );
Thanks all! :)
Worked like a charm.
Topic archived. No new replies allowed.