std::cin input with spaces?

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

    You have to use cin.getline():

    char input[100];
    cin.getline(input,sizeof(input));
    
    0 讨论(0)
  • 2020-11-21 06:34

    You want to use the .getline function in cin.

    #include <iostream>
    using namespace std;
    
    int main () {
      char name[256], title[256];
    
      cout << "Enter your name: ";
      cin.getline (name,256);
    
      cout << "Enter your favourite movie: ";
      cin.getline (title,256);
    
      cout << name << "'s favourite movie is " << title;
    
      return 0;
    }
    

    Took the example from here. Check it out for more info and examples.

    0 讨论(0)
提交回复
热议问题