c++ - How to store a complete sentence with white spaces in a string in cpp? -
this question has answer here:
- tell cin stop reading @ newline 3 answers
- equivalent of console.readline() in c++ 2 answers
i want store "what wrong you?" in string str in cpp when run code stores "what" in ·str·.
how can store complete sentence in string.
#include<iostream> #include<string.h> using namespace std; int main() { string str; cin>>str; cout<<str; }
input:
what wrong you?
output:
what
was answered. here solution:
std::string str; std::getline( std::cin, str);
Comments
Post a Comment