Reading from the command line using stringstream

M

mark lawler

Ok, for my assignment all my classes are working now *hooray* and all I need
to do is set up
the reading from the command line so the user can input commands. Im using
getline and a stringstream to achieve this, however I am not really
achieving much at the moment. Basically it works once, but not the next
time, as as you can see on the code below, the stream isn't filling up
again.

CODE:

string line;
string command;
string argument;
string empty;
stringstream str_stream(line);

While()
{
getline(cin, line);

if(line == "")
{
continue;
}

str_stream << line; //here is my problem, all I want to do is put the
//newly read line into the stream but it doesn¹t
//seem to be doing it. How do I do this?

str_stream >> command;
str_stream >> argument;

str_stream.flush();

...blah blah
}
 

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,764
Messages
2,569,567
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top