mercredi 31 juillet 2019

Getting multiple string input after integer?

I came through this programming question where I need to input multiple strings after inputing a integer. The string also include spaces.

//Program

#include <iostream>
#include<string.h>
using namespace std;

int main() {
int t;
cin>>t;
while(t--){
    string s;
    getline(cin,s,'\n');  //also used cin>>s;
    cout<<"$"<<s<<"$";
}
return 0;
}

Input

2
Hello World
Hello StackOverFlow

Expected Output

Hello World
Hello StackOverFlow

Program's Output

$$$Hello World$

Aucun commentaire:

Enregistrer un commentaire