#include<bits/stdc++.h>
using namespace std;
int main()
{
char *one;
one = new char[1];
cin.getline(one, 5);
cout<<one<<endl;
return 0;
}
This should allocate 1 byte space or 1 character space to the character pointer *one. Now I am taking 5 character input using cin.getline, Why does it output first 4 characters only instead of 5? and why it does not output only 1 character since I have allocated it only 1 character space?
I tried using
for(int i = 0; one[i] != '\0'; ++i) cout<<one[i];
and it does the same thing, it outputs the first 4 characters of my input, not 5 characters. I want it to store only 1 character because I have allocated it only 1 byte space.