Variables in System Commands?

closed account (j6XEy60M)
I'm not sure if this is really much of a noob problem or not, but since I am a noob to C++, I think it's probably best to post it here.

If you're familiar with Control Prompt, you probably know how to send a message to another computer on your network with system("net send ComputerName Hello"). I'm trying to implement that into a C++ console application. But I have no idea how to get the variables posted into the system() command.

So far, my .cpp file looks like this:

#include "stdafx.h"
#include "Common.h"
#include <string>
#include <iostream>
using namespace std;

int send_message()
{
string szMessageComputer;
string szMessage;

system("CLS");
cout << "Send Message " << endl
<< "-------------------------------------------------------------------------------" << endl
<< "To which computer? " << endl;
cin >> szMessageComputer;
cout << "Message: " << endl;
getline(cin,szMessage);
cout << "-------------------------------------------------------------------------------" << endl
<< "Sending Message... " << endl;
}



Any help is appreciated. Thanks for helping the noobs.

1
2
3
4
5
6
7
8
9
10
11
int send_message()
{
  string hostname;
  string message;
  [...]
  cin >> hostname;
  [...]
  getline(cin,message);
  [...]
  system(("net send "+hostname+" "+message).c_str());
}
closed account (j6XEy60M)
It works! Thanks for the quick help.
Topic archived. No new replies allowed.