while ((ch = getchar()) == ' ') equivalent in c++

I believe this is c code, so what is the equivalent of this line in c++?

 
  while ((ch = getchar()) == ' ');
Something like this:

1
2
3
char ch;
while (std::cin.get(ch) && ch == ' ')
    ;

Last edited on
This is the whole code:
1
2
3
4
5
    char getItem() {
        char ch;
        while ((ch = getchar()) == ' ') ; 
        return ch;
    }


I'm confused as to what the while loop means.
It's skipping spaces. When it finally reads a non-space, it returns that character.
So the function could be called "return_next_nonspace_char".
Topic archived. No new replies allowed.