I was tried to make a program that read X lines of input by the user and saved each line on a string.
However, if I tell it to get input 5 times, it only gets input 4 times.
#include <iostream>
#include <string>
using namespace std;
int main()
{
int d, n, i;
cin >> n;
string line[n];
for (i = 0; i < n; i++)
{
getline(cin, line[i]);
}
cout << endl;
for (i = 0; i < n; i++)
{
cout << line[i] << endl;
}
return 0;
}
Basically, if I input "5" to the variable "n", it gets input 4 times, instead of 5.
What is the problem?
Thanks!