Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR CPP

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;
}
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #include #spaces #reading #strings #cpp
ADD COMMENT
Topic
Name
4+4 =