Search code examples
c++charcin

How to cin whole sentence with whitespaces


I have tried:

    char tab[200];
    cin>>tab;
    cout<<tab<<endl;

and I would like to make that even if I input in console A B C all the 3 chars and spaces go into tab at once .


Solution

  • Use cin.getline() instead:

    char tab[200];
    cin.getline(input,200);
    cout<<tab<<endl;