|
-
April 7th, 2008, 09:43 AM
#1
Using getline with cin
Hi. I am trying to get input as a string and when I do this code segment:
Code:
string artist;
cout << "Enter the artist of the album you wish to delete ->";
getline (cin, artist);
it displays the prompt but then "Press any key to continue" and exits the program. iostream.h is included. Am I using getline incorrectly?
-
April 7th, 2008, 09:57 AM
#2
Re: Using getline with cin
You probably are doing a "cin >> somevariable" before that, which
leaves the new-line character in the stream buffer.
See : http://www.codeguru.com/forum/showthread.php?t=439902
-
April 7th, 2008, 09:57 AM
#3
Re: Using getline with cin
Usually this happens because there's already a \n in the stream from a previous cin >>.
-
April 7th, 2008, 10:03 AM
#4
Re: Using getline with cin
Also, it needs to be said: there's no such header as iostream.h in the C++ standard library. The correct header is iostream, no extension.
- Alon
-
April 7th, 2008, 10:05 AM
#5
Re: Using getline with cin
The problem was the extra \n from a previous cin. It's working now. Thanks!
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
|