I am trying to input strings which may contain white spaces.The entire string can be made of white spaces. Here is what I am doing-
#include <bits/stdc++.h>
using namespace std;
char arr[1000][1000];
int main()
{
int t,m=3,n=2;
cin >> t;
while(t--)
{
string str;
for(int i=0;i<m;i++)
{
getline(cin,str);
cout << str[0] << endl;
}
return 0;
}
}
Here t is no of test cases. Say for m=3, I have this input-
1
#T
--
--
For visibility, -
is used to represent white spaces.In actual input,there are white spaces instead of -
.
This is the output I get-
NUL
#
-
Another thing which I tried is this-
for(int i=0;i<m;i++)
{
for(int j=0;j<n;j++)
cin >> arr[i][j];
}
where m=3,n=2 for the example above.But printing this arr gives me following output-
#T
NULNUL
NULNUL
I am not sure why I am getting this output.Why am I getting NUL
instead of white spaces.Also in the first code, the output I get is NUL
before #
,why is that?