While using getline in a c++ code it is taking the first string as the null character probably and thus missing the last string from the input. Probably I am missing out something regarding the use of getline. Any help is appreciated The code with input and output is below:
CODE
#include
#include
using namespace std;
int main() {
short int t,i;
cin>>t;
string a;
while(t–)
{
getline(cin,a);
cout<<"length of string is "<<a.length()<<endl;
for(i=0;i<a.length()/2;i+=2)
{
cout<<a[i];
}
cout<<endl;
}
return 0;
}
INPUT
4
hello
understand
think
programming
OUTPUT
length of string is 0
length of string is 5
h
length of string is 10
udr
length of string is 5
t