Use ch != 32 instead.
But do so only if you are required to do that. Using character codes directly is a bad style and can lead to different problems
Edit: JLBorges provided a workaround handling both style problem and different problems (your program will either work or crash with assertion failure noticing you that you just avoided serious problem)
constint SPACE = 32 ; // hard-coded code-point for space (32)
assert( SPACE == ' ' ) ; // assert that the assumption holds: code-point for space is 32
char ch ;
while( std::cin.get(ch) && ch != SPACE ) { /* .... */ }