0

It didn't take the input correctly using getline(cin,s).It takes 1st input as empty space.can anyone please solve this for example code is

#include<bits/stdc++.h>
#include<string>
using namespace std;
int main()
{
int t;
cin>>t;
for(int i=0;i<t;i++)
{
   string s;
   getline(cin,s);
   cout<<s<<endl;
 }
 }

if input is: 5 In keyboard the keys are arrange in the order qwertyuiopasdfghjklzxcvbnm and Welcome to CODE COMBAT hffoufcutjcufvhk iuhiogu upug sngkn rkgnf fhg ogi goijng dfoghgreh f fofhh

the ouput is:

In keyboard the keys are arrange in the order qwertyuiopasdfghjklzxcvbnm and Welcome to CODE COMBAT hffoufcutjcufvhk iuhiogu upug sngkn rkgnf fhg ogi

Venkatesh
  • 1
  • 1
  • There is nothing wrong with the code. In your input, you have given space after 5. So, it takes the value 5 as the integer t and the rest starting from the space as the cin value. Try removing the space after 5 and you will get the correct output. – SAKSHI GOYAL Jan 23 '22 at 13:27

0 Answers0