Hi folks, I'm only just getting into classes. I wrote a simple one to get employee imformation. When I got to read in the name string it just skips right past it, with this output:
Enter name: Enter age: <cursor here>
//lets me proceed
I used getline(std::cin, strName); to read in the name as I was taught this would allow whitespace (for a full name). The getline works as expected when I use it in main, but something is up with it being in this class?
I never get my head around strings / C-style strings!
I'm ashamed to say I do not know how to do that! I will look it up. I'm learning from a website and book (with the website having a substantial head start), but I trust the book will eventually teach this :)
Edit: I put this std::cin.ignore(1000, '\n'); which worked.
its easy to understand. so when you type something on the keyboard, it is stored in a buffer, to be later grabbed by the program. c++ reads in from the buffer into a variable up until it hits white space (ie [space] tab newline etc) so getline reads in all of thats in the buffer, so if you already had junk left in the buffer, it will be read in with getline, giving it a value unintenionally. if you write cin.flush() above it, it should work
edit: ignore the commands i told you to write. instead do:
http://www.cplusplus.com/forum/beginner/107404/#msg582623