This question was useful: How does while (std::cin >> value) work? but doesn't answer a few of my questions.
When running
#include <iostream>
int main() {
int sum = 0; int value = 0;
while (std::cin >> value) {
sum += value;
}
std::cout << sum << std::endl;
}
I then pass something like:
1 2 3 4 5 \n
to the interpreter (I guess not an interpreter, I mean the CLI). My question is how is this stored, how does it "know" to skip the spaces, how are the spaces even processed. I understand it somehow iterates over these but can't quite figure out how... Does it store an intermediate array? Is it perhaps more equivalent to something like this in pseudocode:
input = "1 2 3 4 5 \n"
value = input.get_next() # we look for the next non-space character
if type(value) != int:
break
else:
sum += value
also any advice on how I can figure this out by myself would be appreciated.