cin >> string;
If you type a string with spaces, you only get the first word. Why is this?
cin >> string;
If you type a string with spaces, you only get the first word. Why is this?
cin reads a string up to (but not including) the first whitespace it encounters. Use cin.getline instead :
first argument is your string , second speicifies the max input number , third is the delimeter (its '\n' by default so you don't have to include it).Code:cin.getline(mystring, sizeof(mystring), '\n');
hope this helps
My Tutorials :
- Bad programming practices in : C
- C\C++ Tips
(constrcutive criticism is very welcome)
- Brain Cell
Of course when mystring is char* ...Originally Posted by Brain Cell
Last edited by Micko; 04-03-2005 at 10:25 AM.
Gotta love the "please fix this for me, but I'm not going to tell you which functions we're allowed to use" posts.
It's like teaching people to walk by first breaking their legs - muppet teachers! - Salem
Bang on, baby!Originally Posted by Brain Cell
Originally Posted by Brain CellActually, not quite, although Brain Cell may have gotten that from something I posted(which was incorrect--sorry!). It's actually the >>operator that is programmed to skip leading whitespace it sees, then start reading in data, and finally stop reading data when it encounters a whitespace character(space, tab, or newline)--not cin. If you learn about file I/O, you will see that the >>operator does the same thing with other streams besides cin.Bang on, baby!
(I'll have to try and search for that post of mine, and correct it. )
Last edited by 7stud; 04-03-2005 at 01:38 PM.