0

how can i pass a variable to command?
ex..

#include <iostream>
using namespace std;
int main(int argc, char *argv[])
{
string ip

cout << "Enter an ip";
cin >> ip;
system("ping ip"); //// this is the problem. how do i enter the value of "ip" here?

    system("PAUSE");
    return EXIT_SUCCESS;
}
2
Contributors
2
Replies
3
Views
8 Years
Discussion Span
Last Post by eviocg
0

you have to create one big string that includes all the variables

#include <iostream>
using namespace std;
int main(int argc, char *argv[])
{
string ip
string command;
cout << Enter an ip;
cin >> ip;
command = "ping " + ip;
system(command.c_str()); //// this is the problem. how do i enter the value of "ip" here?


    system("PAUSE");
    return EXIT_SUCCESS;
}
0

i see. thank you. I knew there had to be simmple way of doing this, but it just didnt hit me.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.