Please help me to solve the following program
#include<iostream>
#include<cstring>
using namespace std;
int main(){
const int size=5;
char name1[size], name2[size];
cin.getline(name1, size);
cin.getline(name2, size);
cout<<"Name 1: "<<name1<<endl;
cout<<"Name 2: "<<name2<<endl;
return 0;
}
When i enter more than 5 letters for name1, it skips the second cin.getline code. It directly show the cout statements. It does not get the value for name2
It want this program to take only 4 character for name1, and it should get next input for name2. How to do this, without using string?