0

<< moderator edit: split thread from [thread=8544]here[/thread] >>

i've found that somehow cin has a '\n' by default and you should use cin.ignore() to clear the input stream.

hope this helps. :idea:

3
Contributors
4
Replies
5
Views
13 Years
Discussion Span
Last Post by Dogtree
0

>> I thought cin.get() didn't work with strings... or am I wrong?
What kind of strings are you talking about? C++ supports two types of strings: the C-style string that's just an array of char terminated by '\0', and the std::string class. You're correct if you mean the std::string class, otherwise you're wrong. cin.get() is overloaded with the same signature and functionality as cin.getline(), with the one obvious difference that cin.get() does not extract the delimiter character from the stream while cin.getline() does.

0

Exactly, that's why I thought this statement was a bit weird:

string FullTimePartTime; 

char response[256];

cout << "\n\nDO YOU NEED TO CALCULATE FULLTIME OR PARTIME EXPENSES? "; 
cin >> FullTimePartTime; // cin used with string
0

How is that weird? cin's >> operator is overloaded for plenty of different types. If you include <string>, that includes the std::string class.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.