std::cin input with spaces?

前端 未结 8 1214
再見小時候
再見小時候 2020-11-21 05:41
#include 

std::string input;
std::cin >> input;

The user wants to enter \"Hello World\". But cin fails at the spa

8条回答
  •  日久生厌
    2020-11-21 06:09

    The Standard Library provides an input function called ws, which consumes whitespace from an input stream. You can use it like this:

    std::string s;
    std::getline(std::cin >> std::ws, s);
    

提交回复
热议问题