I know this is asked a lot, i've looked it up and found several answers to my problem, but it just won't do. The code looks like this, i'll explain later what I want to do:
Ok so this is pretty straightforward: I want the console to ask me some details about a movie, and then print it nicely. The problem is that this will only take one word for every input. While looking up I found something about getline(); this is where it gets tricky.
When I use getline(cin, title); (etc.) instead of cin << title; the console prints "Title? Year? " on one line and asks only for one input. Then it prints "medium? " and asks for a second input, then it prints the input. So suddenly I have only two inputs instead of three, I don't understand what's happening. In short, this doesn't work:
Thx for the answers, though this isn't really helping (:-p). I still don't have a clue why he skips the first input, so I don't hav any clue how to fix this.
edit: I just copy/pasted the code I wrote on this page into eclipse ... it seems to work on a different computer D; I love the magic in informatics ... !
Well, like is explained in detail in the post I linked, the operator>> extracts input from the stream up to white space, but discards any leading white space. So if you use it more then once any white space that is left in stream is summarily discarded by the next >>. Unfortunately, this means if you are trying to get more then 1 word at the same time you have to use multiple >>. This is where getline comes in. BUT, getline does NOT discard leading white space. So you have to do it manually in the code with a black cin.getline() or something similar. There's also cin.ignore(numberofchars, sentinelchar). With ignore the numberofchars represents the maximum number of chars that ignore will read out of the stream and discard. sentinelchar is a char that, once ignore reaches it, will stop before it hits numberofchar, but which it will still extract and discard. So, for instance cin.ignore(1024, '/n') would extract either 1024 characters from the stream and discard them, or all characters up to and including a newline char, which would also be discarded.