How can I use cin to input a space to a char?

Is there anyway that I can use cin to pass a whitespace to a char object? For instance, as in the code shown below:

1
2
3
4
5
6
7
8
#include <iostream>
using namespace std;
int main()
{
    char ch;
    cin >> ch;
    cout << "ch is " << ch << endl;
}

If I try to input a whitespace here to pass it to ch, it won't
do because it seems that whitespace is simply ignored every time I key in one. Is there anyway that I can make this work? Thanks!
Formatted input skips whitespace characters.
Use unformatted input: std::cin.get(ch);
1
2
3
4
5
6
7
8
9
#include <iostream>
#include <string>
using namespace std;
int main()
{
    string ch;
    getline(cin, ch);
    cout << "ch is " << ch << endl;
}


i like "getline" more then "get"

if you don't mind not using char
To MiiNiPaa: Get it. Really Appreciate it.
To DyavolskiMost: I'm aware that I could have used getline on an string object in this case, and I was just wondering about what I should do with char object, but thanks anyway.
Topic archived. No new replies allowed.