-2

I want to store "What is wrong with you?" in a string str in cpp but when I run this code it only stores "What" in ·str·.

How can I store the complete sentence in the string.

#include<iostream>
#include<string.h>
using namespace std;
int main()
{
    string str;
    cin>>str;
    cout<<str;
} 

Input:

What is wrong with you?

Output:

What
Yu Hao
  • 119,891
  • 44
  • 235
  • 294
user2112174
  • 29
  • 1
  • 1
  • 3

1 Answers1

1

was already answered. But here is the solution:

std::string str; 
std::getline( std::cin, str);
Tirma
  • 664
  • 5
  • 16