如何存储一个完整的句子与空白的字符串在cpp

How to store a complete sentence with white spaces in a string in cpp?

本文关键字:句子 空白 字符串 cpp 一个 何存储 存储      更新时间:2023-10-16

我想在cpp的字符串str中存储"What is wrong with you?"但是当我运行这段代码时,它只在·str·中存储"What" .

如何在字符串中存储完整的句子。

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

What is wrong with you?
输出:

What

已被回复。但这是解决方案:

std::string str; 
std::getline( std::cin, str);