在C++中,getline函数用于从输入流中读取一行字符串。其基本语法如下:
#include <iostream>#include <string>int main() { std::string line; // 从标准输入流中读取一行字符串 std::getline(std::cin, line); // 输出读取的字符串 std::cout << "You entered: " << line << std::endl; return 0;}在上面的示例中,getline函数从标准输入流std::cin中读取一行字符串,并将其存储在line变量中。然后,将读取的字符串输出到标准输出流std::cout中。




