I would like to know how to read a line of text, that the user inputs, into a string... I can't use cin because it needs to be able to work for more than one word. Thank you for any help!!
Printable View
I would like to know how to read a line of text, that the user inputs, into a string... I can't use cin because it needs to be able to work for more than one word. Thank you for any help!!
use getline() ...
note : if using VC++, depending on the version, you mightCode:#include <iostream>
#include <string>
using namespace std;
int main()
{
string line;
cout << "Enter a line of input > ";
getline(cin,line);
cout << endl << "user input was > " << line << endl;
return 0;
}
need to enter return twice after the user input. DinkumWare
has a fix for this on their web page.
I have a linux machine and getline is not working on it... I was wondering if getline might be for windows only or something. Thank you very much for any help.
getine() is not Windows specific, so it should
work under linux. I can test that tomorow.
Are you using g++ ? Maybe try my test program
and see if it works. If it works, but your code
doesn't, maybe post your code.