#include <iostream>
#include <string.h>
#include <bits/stdc++.h>
#include <cstring>
using namespace std;
int main()
{
int t;
cin>>t;
while(t--)
{
string str;
getline(cin,str);
int n=str.size();
char ch[n+1];
strcpy(ch,str.c_str());
cout<<ch<<endl;
}
return 0;
}
What test input are you using?
Edit:
When using getline
after reading an int
, you need to skip the remainder of the line after the int
:
#include <iostream>
#include <string.h>
#include <bits/stdc++.h>
#include <cstring>
using namespace std;
int main()
{
int t;
cin>>t;
cin.ignore(std::numeric_limits<streamsize>::max(), '\n');
while(t--)
{
string str;
getline(cin,str);
int n=str.size();
char ch[n+1];
strcpy(ch,str.c_str());
cout<<ch<<endl;
}
return 0;
}
5 Likes
got it! thank you!!
1 Like