<< 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:
<< 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:
I thought cin.get() didn't work with strings... or am I wrong?
>> 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.
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
How is that weird? cin's >> operator is overloaded for plenty of different types. If you include <string>, that includes the std::string class.
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.