Using cin for char array

Here is my code:

#include <iostream>
using namespace std;

int main(){
    char inp[5], out[4];
    cin >> inp >> out;
    cout << inp << endl;
    cout << out << endl;
    system("pause");
    return 0;
}

when I type:

12345 6789

It gives me:

6789

Why I failed to save the 5 words char array ‘inp’ and it showed nothing? The second input looks normal though. However, when I set out[3] or out[5], it seems to work alright? It seem that two char array of [5] then followed by [4] would cause problem…

Leave a Comment