Code for getting multiple words in a string from user

前端 未结 5 375
独厮守ぢ
独厮守ぢ 2021-01-20 14:04

Actually i want the user to enter a line of string having multiple words in it for example \"My name is ABC\". What is the C/C++ code for this purp

5条回答
  •  时光取名叫无心
    2021-01-20 14:33

    You can use std::getline() to get a line from std::cin.

    #include 
    #include 
    using namespace std;
    
    int main () 
    {
      string name;
      cout << "Enter Name: ";
      getline (cin,name);
      cout << "You entered: " << name;
    }
    

提交回复
热议问题