include spaces while reading strings in cpp

Solutions on MaxInterview for include spaces while reading strings in cpp by the best coders in the world

showing results for - "include spaces while reading strings in cpp"
Joshua
01 Jun 2016
1Using getline() will help you.
2Example: 
3
4int main()
5{
6   std::string name, title;
7
8   std::cout << "Enter your name: "; //Name: Robert De Niro
9   std::getline(std::cin, name);
10
11   std::cout << "Enter your favourite movie: "; // title: The Irishman
12   std::getline(std::cin, title);
13
14   std::cout << name << "'s favourite movie is " << title;
15}
16