How to split a string to separate variables with a space - C++

  • Thread starter Thread starter VinnyLoneDev
  • Start date Start date
V

VinnyLoneDev

Guest
I'm trying to make a Command-Line-Interface in C++ for fun. I need to have multiple arguments, so I need my string to be separated to different variables. Not to change the string to change what line a word is showed on.

EXAMPLE

>echo hello
hello
>echo I am cool
I am cool


What I have so far is a simple program that asks for input. stores it into a variable and does nothing with it.

(This is stored in a function because there is stuff that launches it.)


void Foo() {
string com = "";

cout << "C++ Computer Operation" << endl;
for ( ; ; )
{
cout << endl;
cout << "> ";
getline(cin, com, " ")
if ( com = "echo" ):
{
cout << arg;
}

}
}


And I am sorry for using the name 'Foo'

Continue reading...
 
Back
Top