在c ++中用空格读取输入

use*_*065 1 c++ string input

目前我正在读取带有空格的输入.

int main() {
  char str[100];
  string st;
  cin.getline(str,100);
  st=str;
}
Run Code Online (Sandbox Code Playgroud)

我想利用字符串附带的函数,所以我将输入读入字符串.有没有其他方法可以直接将输入读入字符串,也允许空格.

The*_*Saw 5

如果你要使用std::string对象,只需使用std::getline.

std::string st;
std::getline(std::cin, st);
Run Code Online (Sandbox Code Playgroud)