Link to home
Start Free TrialLog in
Avatar of fattumsdad
fattumsdad

asked on

String conversions....

Hello all,

I wrote this little program as a LAN messenger.  Being very new to C++, I was quite proud!  However, when I run the program, it takes each string in the "message" and sends it seperately.  The program basically uses "net send" to send messages.  How do I keep every word in the sentence from being sent as a seperate message?  Here is the code so far:

#include <iostream>
#include <stdlib.h>

using namespace std;

int main(int argc, char *argv[])
{
  std::string target;
  std::string GetStarted = "net send ";
  std::string spacer = " ";
  std::string messg;

  cout << "Welcome to LAN Messenger 1.0 beta 1.\n";
  cout << "Enter /h in any field at anytime for help.\n";
  cout << "\n";
  system("Pause");

Begin:
  system("CLS");
  cout << "Target: ";
  cin >> target;
  if(target == "/h" || target == "/H")
  {
      system("CLS");
      cout << "*Target* <- Enter target users network name, or computer name.\n";
      cout << "*Message* <- Enter your message.\n";
      cout << "To change target users, enter / in the message field.\n";
      cout << "To view help file, enter /h in any field.\n";
      cout << "To exit, enter // in any field.\n";
      cout << "\n";
      system("Pause");
      goto Begin;
  }
  if(target == "//")
  {
      system("CLS");
      cout << "\n";
      cout << "Connection terminated.\n";
      cout << "\n";
      system("Pause");
      return 0;
  }        
 
 
  do
  {
      system("CLS");
      cout << "Connection to " << target << "\n";
      cout << "Message: ";
      cin >> messg;
     
      if(messg == "//")
      {
          system("CLS");
          cout << "\n";
          cout << "Connection to " << target << " terminated!\n";
          cout << "\n";
          system("Pause");
      }  
     
      if(messg == "/")
      {
          goto Begin;
      }    
     
      if(messg == "/h" || messg == "/H")
      {
          system("CLS");
          cout << "*Target* <- Enter target users network name, or computer name.\n";
          cout << "*Message* <- Enter your message.\n";
          cout << "To change target users, enter / in the message field.\n";
          cout << "To view help file, enter /h in the message field.\n";
          cout << "To exit, enter // in the message field.\n";
          cout << "\n";
          system("Pause");
      }    
               
      std::string command = GetStarted + target + spacer + messg;
      system(command.c_str());
      system("CLS");
  }while (messg != "//");  

  return 0;    

}

Any and all help is greatly appreciated!  

Regards,

Tony
SOLUTION
Avatar of mrwad99
mrwad99
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ASKER CERTIFIED SOLUTION
Avatar of jkr
jkr
Flag of Germany image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
>> it'd be better to use...

Yeah.

1851971 : 32762 - what can I say.  Experience shows through *again* :)
If using VC++ also it is essential to read

http://support.microsoft.com/default.aspx?scid=kb;EN-US;q240015 

first though.
Avatar of fattumsdad
fattumsdad

ASKER

JK,

You never cease to amaze me!  Thanks again!

R/
Tony