tags:

views:

615

answers:

1

I wish to read from cin in C++ from the current position up until a newline character into a string. The characters to be read may include spaces. My first pass fails because it stops on the first space:

string result;

cin >> result;

If cin is given:

(cd /my/dir; doSometing)\n

The variable result only gets:

(cd

I would think I should be able to use stream manipulators to accomplish this, but the skipws was not quite right in that it throws carriage returns in with spaces and tabs, plus it sounds like that is for leading whitespace to be skipped.

Perhaps I need to use streambuf something like this?

streambuf buf;

cin >> buf;
+6  A: 
std::string str; 
std::getline( std::cin, str);
Samuel_xL
Note (since I just got burned by this): Does not appear to work with AIX 5.1. I had to use `fgets` defined in stdio.h.
Pete