错误:函数"getLine"必须具有原型

Error: The function "getLine" must have a prototype

本文关键字:原型 getLine 函数 错误      更新时间:2023-10-16

我正在尝试使用 getLine 读取带有空格的字符串,但我收到错误">错误:函数"getLine"必须有一个原型。即使在包括使用命名空间 std 之后,我也会收到此错误;

   void buildAhardCodedSQL4() 
    {
       cout << "Enter source : ";
       getLine(cin,source);
    }

getLine(cin,source);替换为getline(cin,source);

有关如何使用 getline() 的详细信息,请参阅以下内容:http://www.cplusplus.com/reference/string/string/getline/

阅读手册:

http://en.cppreference.com/w/cpp/string/basic_string/getline

#include <string>
#include <iostream>
#include <sstream>
int main()
{
  // greet the user
  std::string name;
  std::cout << "What is your name? ";
  std::getline(std::cin, name);
  std::cout << "Hello " << name << ", nice to meet you.n";
  // read file line by line
  std::istringstream input;
  input.str("1n2n3n4n5n6n7n");
  int sum = 0;
  for (std::string line; std::getline(input, line); ) {
    sum += std::stoi(line);
  }
  std::cout << "nThe sum is: " << sum << "n";
}