mercredi 27 décembre 2017

String concatenation with user input in C++

I tried to write a code which gets an input from the user and concatenate with another string but it doesn't work well. The code is down below,

#include<iostream>
using namespace std;
int main() {
    string s1="Hi ";
    string s2;
    cin>>s2;
    s1=s1+s2
    cout<<s1;
    return 0;
}

Input: this is how it works

Expected Output: Hi this is how it works

But it didn't work as I expected.

The output of my code: Hi this

Can anybody help me?

Aucun commentaire:

Enregistrer un commentaire