Hi all, so I've been trying to put 3 different data types into 3 different arrays from an input file. However after the first 3 items it can't seem to read in the rest of the values properly. I can't seem to find the bug, if anyone can help me it'l be much appreciated. Thanks!
so i tried that, but it still didn't work. After putting the cin.ignore i get no output, I'm also on linux(if that makes a difference). I get what your trying to say, but I don't think thats the problem :/
Oh. std::cin was an example. You should apply operation to whichever stream you are operating on. In your case it is inputFile. inputFile.ignore();. And I still suggest to use >> ws. It ever says so in article I linked.
Also I want to say that correct condition for loops is index < 3. In current state it will try to access namesAr[3] eventually which can lead to crash.
The difference is that ignore(std::streamsize count = 1, int_type delim = Traits::eof())3 indiscriminately discards characters until it either discards count characters, finds the delimiter (specified by the second argument delim) or hits the end of the stream. std::ws is only used for discarding whitespace characters from the beginning of the stream.
If you are mixing formatted input with unformatted input and you need to discard residual whitespace, use std::ws. Otherwise, if you need to clear out invalid input regardless of what it is, use ignore(). In our example, we only need to clear whitespace since the stream consumed your input of "John" for the name variable. All that was left was the newline character.