Program skips cin.getline()

前端 未结 5 1795
野的像风
野的像风 2020-12-19 12:18

I have made this program, It get the users adress, name and work. Then It puts it all into one string and outputs that string. (I know there are better ways to do this)

5条回答
  •  醉话见心
    2020-12-19 12:54

    The free function std::getline operates on std::strings, which are much easier to deal with than character arrays. Particularly, std::getline allows for arbitrarily-large input lines.

    Try this:

    std::string str;
    std::string adrs;
    std::string name;
    std::string wrk;
    cout<<"Enter your name and press ENTER: ";
    std::getline(std::cin, name);
    cout<<"\nEnter your adress and press ENTER:";
    std::getline(std::cin, adrs);
    ...
    

提交回复
热议问题