Answers for "reading a string in c++ with spaces"

C++
1

include spaces while reading strings in cpp

Using getline() will help you.
Example: 

int main()
{
   std::string name, title;

   std::cout << "Enter your name: "; //Name: Robert De Niro
   std::getline(std::cin, name);

   std::cout << "Enter your favourite movie: "; // title: The Irishman
   std::getline(std::cin, title);

   std::cout << name << "'s favourite movie is " << title;
}
Posted by: Guest on March-18-2021
7

how to make string get spaces c++

string s;
getline(cin,s);
Posted by: Guest on June-02-2020

Browse Popular Code Answers by Language