Accepting [SPACE] as an input

I'm sure this is simple and obvious but I've been through books and Googled and found nothing.

All I want to do is accept [SPACE] as input for a variable. At present I'm doing an exercise on switches which requires that input characters be translated, so for example uppercase chars become lowercase and [SPACE] becomes _ (underscore).

So what do I need to do so that when the user inputs [SPACE] [RETURN], the program accepts that as something I can work with?

Thanks in advance!
The following read each character until a newline
1
2
3
4
5
6
7
char c;
do
{
    cin.get(c);
    // you may want to do something in here
}
while ( c != '\n' );

You can also get the entire line to a string ( with getline ) and then loop the character of the string
Excellent, thanks! I actually cut out the do-while statement for mine, as the point is to have the user enter [char] [RETURN].
Topic archived. No new replies allowed.