The program seems to run with just the iostream header file on its own, why arent the others required? Just curious
Printable View
The program seems to run with just the iostream header file on its own, why arent the others required? Just curious
Due to the way the standard library is usually implemented, some standard headers include others internally, and thus the symbols from those other headers become available, too.
The important thing is that this is only a side effect, and a completely unpredictable at that. A different compiler, even a different standard library, might be implemented differently and make your program fail.
Hmm I'm having another slight problem, possibly I'm using the wrong syntax for storing the string into variable msg.Code:#include <iostream>
#include <dos.h>
#include <string>
using namespace std;
int select;
string host, msg;
string systemSender = "net send ";
char getinfo()
{
system("cls");
cout<< "------------------------\n"
<< "Potato Net Sender v0.01\n"
<< "------------------------\n\n";
cout<< "Hostname: ";
cin>> host;
cout<< "Message: ";
getline (cin, msg, '\n');
cin>> msg;
}
char send()
{
systemSender += host + " " + msg;
system(systemSender.c_str());
}
char selection1()
{
cin.get();
getinfo();
send();
}
int exit_app()
{
return 0;
}
char intro()
{
system("cls");
cout<< "------------------------\n"
<< "Potato Net Sender v0.01\n"
<< "------------------------\n\n";
cout<< "1. Send a message to another computer\n"
<< "2. Exit\n\n";
cout<< "Selection: ";
cin>> select;
if (select == 1)
{
selection1();
}
else if (select == 2)
{
exit_app();
}
else
{
system("cls");
cout<< "\nYou must enter either 1 or 2 to proceed\n\n";
cout<< "Press any key to try again...";
cin.get();
selection1();
}
}
int main()
{
intro();
cin.get();
}
Whenever I type a message with more than one word it will just net send the first word, it doesnt seem to be capturing the whole string.
For Example:
That will send only "Hello" through net send.Code:Hostname: 127.0.0.1
Message: Hello this is a test
That's probably because net send only sends its first argument. You must make sure quotes appear on the command line, i.e. the string you send to system.
Yeah but I want to be able to store what I type in the string without the quotes, isnt that possible?
[edit]
Doesnt work with quotes anyway
> systemSender += host + " " + msg;
> system(systemSender.c_str());
If you're just being hackish and using system() to do all the dirty work for you, then you need to be more careful with the command line you construct.
Say
to include the message you want to send in double quotesCode:systemSender += host + " \"" + msg + "\"";
system(systemSender.c_str());
What else could I use other than system() ? I use it cause its all I know so far, also, I dont quite understand that code you typed, and it gives me the same result as before
Does this work?
> What else could I use other than system() ?Code:system( "net send \"hello world\" ");
Like the proper sockets interface to write true networking applications.
You can basically do what you have at the moment using a batch file.