Here, firstly i am trying to take size of an array as input, and then that number of students as input again. I have used getline(cin, arr[i]) to include white space as input to store both the first name and last name. My codes are shown below. But, it is skipping arr[0] and starting to store the values starting from arr[1]. If I don't use variable lenght array it still skips arr[0]. Please help.
#include <iostream>
#include <string>
using namespace std;
int main()
{
int s;
cout<<"Enter the number of students\n";
cin>>s;
string arr[s];
cout<<"Enter the name of the students\n";
for (int i=0;i<s;i++){
getline(cin, arr[i]);
cout<<"The name of the students are:\n";
for (int i=0;i<s;i++){
cout<<i<<"="<<arr[i]<<"\n";
}
return 0;
}
OUTPUT:
Enter the number of students
4
Enter the name of the students
John Smith
Alfred Kox
Mike Holfman
The name of the students are:
0=
1=John Smith
2=Alfred Kox
3=Mike Holfman
Why arr[0] is not storing any thing and taking only 3 inputs? I can't figure out, what is wrong in here, please help.