std::cin input with spaces?

前端 未结 8 1233
再見小時候
再見小時候 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:26

    I rather use the following method to get the input:

    #include 
    #include 
    
    using namespace std;
    
    int main(void) {
        string name;
    
        cout << "Hello, Input your name please: ";
        getline(cin, name);
    
        return 0;
    }
    

    It's actually super easy to use rather than defining the total length of array for a string which contains a space character.

提交回复
热议问题