Hi,
When I want to get a string with getline function, it jumps from this statement without getting string . Because I get an integer number before it and the \n is pressed . To solving this problem I use cin >> ws before getting string with getline function . Now when I want to enter white spaces in beginning of string , this white spaces is ignored .
What can I do to solving this problem ?
Thanks ......
Behi Jon
0
Light Poster
Recommended Answers
Jump to Post
cin.ignore()
I think.
Jump to PostThis is what I would do.
#include <iostream> #include <string> using namespace std; int main() { int myInt; string myString; cin >> myInt; cin.ignore(); //use this it ignores the last '\n' character getline(cin, myString); system("PAUSE"); return 0; }
All 6 Replies
twomers
408
Posting Virtuoso
sfuo
111
Practically a Master Poster
sfuo
111
Practically a Master Poster
Behi Jon
0
Light Poster
sfuo
111
Practically a Master Poster
Behi Jon
0
Light Poster
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.