I am trying to store individual character(including the spaces) of a sentence in a char array like "Do or die" but whenever I print the array (char arr) it does not print the last character in the array i.e. 'e'.
Can somebody tell why is this happening . I am a beginner in c++.
#include<iostream>
using namespace std;
int main()
{
int n;
cout << "Enter the length of the array\n";
cin >> n;
char arr[n + 1];
cin.ignore(n, '\n');
cout << "Enter the characters of the array\n";
cin.getline(arr, n);
for(int i = 0; i < n; i++)
cout << arr[i] << endl;
return 0;
}