|
-
October 19th, 2002, 04:38 PM
#1
reading text from the user
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!!
-
October 19th, 2002, 07:23 PM
#2
use getline() ...
Code:
#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;
}
note : if using VC++, depending on the version, you might
need to enter return twice after the user input. DinkumWare
has a fix for this on their web page.
-
October 20th, 2002, 12:17 AM
#3
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.
-
October 20th, 2002, 03:33 PM
#4
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.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|