system variables?

C

cheesywillie

How do i get a string variable to be included into a system command?
For example:

#include <cstdio>
#include <cstdlib>
#include <iostream>

using namespace std;

int main(int nNumberofArgs, char* pszArgs[])
{
string reply;
cout << "What do you want to say? ";
cin >> reply;
system("net send 192.168.***.*** "); //how do i get the string
variable, "reply" after the IP?
system("PAUSE");

return 0;
}

any help would be appreciated thx
 
V

Victor Bazarov

How do i get a string variable to be included into a system command?
For example:

#include <cstdio>
#include <cstdlib>
#include <iostream>

using namespace std;

int main(int nNumberofArgs, char* pszArgs[])
{
string reply;
cout << "What do you want to say? ";
cin >> reply;
system("net send 192.168.***.*** "); //how do i get the string
variable, "reply" after the IP?
system("PAUSE");

return 0;
}

This is usually accomplished by having a _variable_ of type 'std::string'
and forming it from different parts during run-time, and then passing it
to 'system' function:

string command("net send blah ");
system((command + reply).c_str());

V
 

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

Forum statistics

Threads
473,796
Messages
2,569,645
Members
45,371
Latest member
TroyHursey

Latest Threads

Top