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;
}

Recommended Answers

All 2 Replies

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;
}

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

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.