Hello, I am doing problems on hackerrank, and had a question that involved putting values into an array or a vector. I have managed to get this to work but wondering how exactly it does work.
So the input is given as one line input, ie - 1 3 5 7 and each of those ints need to be a different element in the array or the vector, as seen in my code below I done this with a loop, but I am wondering exactly how this works, when the whitespace is read, does the array/vector just know to move passed and ignore it?
The vector doesn't do anything. The std::istream (cin)'s operator >> is what does the magic. It parses the input delimited by whitespace, and puts the extracted value into your int input.
Internally, there are probably different possible implementations for operator >>, but it probably just looks at each character until it finds a character matching std::isspace, and then converts the digits into an int (like stoi or atoi).
Thank you, now that you mention istream, i do remember reading something about that back when i started learning. I guess i will need to go back over it :) thanks again