在C++中使用cin

Hik*_*aki 1 c++ cin char

我想使用cin,我使用char作为int类型(你这样称呼它吗?)它只显示一个键入的字母.我怎么能得到整句话?

gre*_*olf 5

既然你正在使用c ++,为什么不使用std::string呢?这样的事情应该做你想要的:

#include <iostream>
#include <string>

int main()
{
  using namespace std;
  string sentence;
  cout << "Enter a sentence -> ";
  getline(cin, sentence);
  cout << "You entered: " << sentence << endl;
}
Run Code Online (Sandbox Code Playgroud)