vendredi 27 juillet 2018

How can i exit a loop in c++ if i press enter?

I want to exit a loop if press enter in codeblocks(c++). So this is my code

    #include<bits/stdc++.h>
    using namespace std;
    int main()
    {
    string s="";
    char ch;
    while(1)
    {
        cin>>ch;
        s+=ch;
    }
    cout<<s<<endl;
    return 0;
    }

Aucun commentaire:

Enregistrer un commentaire