|
-
March 20th, 2002, 07:49 PM
#1
getline
I'm a new user to C++ (I know up to some intermediate Java though). Java has the readln function that can take a whole line and put into a string. I know C++ doesn't do strings aside from char [max] and the string class, so I did #include <string> and the string works well, except when I try to import a line into the string. For instance,
cout << What is your name?
I know cin only reads up to the space and sends this back. So I did some research and foudn getline. However, getline works fine only when it is the first input/output i'm doing in the program( in my main class). If I do some input in a menu style function, and then call on an input function, where I ask for the person's name ala:
string name;
cout << "what is your name?";
getline(cin, name);
cout << "hello " << name;
cout << "how old are you?"
cin >> age;
The program will not even stop to let me input my name. For instance:
What is your name? Hello, How Old are you?
It then pauses for me to input my age. What's wrong here though???
Is there a simple way to input a line into string or cstring or anything like that? ANy help would be GREATLY appreciated.
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
|