I want to extract 6 chars (including '\n') from input to an array and ensure that the input is correct by getting the new line character at an specific place in the array. This is what I did but I cant fix it. If the user enters more than 5 characters the loop repeats but the remaining characters still are in the stream. With the cin.ignore('\n') I get an infinite loop with no character in the stream.
do
{
cout << "Please log in: \n";
cin.get(username, 6);
cin.ignore('\n');
if (username[5] != '\n')
cout << "\nYour username should be 5 digits!\n\n";
} while (username[5] != '\n');