错误:函数"getLine"必须具有原型
Error: The function "getLine" must have a prototype
我正在尝试使用 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";
}
相关文章:
- Seg Fault Issue C++ (file IO / getline)
- 函数向量_指针有不同的原型,我可以构建一个吗
- 当用户键入分隔符时,停止getline()输入
- 功能原型的目的
- getline() 的原型/库是什么;
- 错误 没有与参数列表匹配的重载函数"getline"实例
- 如何在 c++ 中使用 ',' 作为 getline 分隔符
- 错误:调用'getline'没有匹配函数
- 如何在 c++ 中使用 getline 从文件中读取字符串?
- 具有enable_if外部类原型的模板类构造函数定义
- 函数如何通知用户它基于函数原型抛出异常?
- 在C++中包含原型文件的正确方法是什么?
- 将 getline() 与文件一起使用
- 在函数中拥有函数原型的目的是什么?
- 我有三个 getline,但是一旦编译,输入就太多了
- 在 std::getline 和 std::cin 期间卡在循环中
- 为什么 getline() 不读取文本文件中的所有内容?
- 有没有办法在不使用 getline() 的情况下从.csv文件中读取?
- 确切地说,如何解释 std::getline(stream, string) 函数在C++中填充的字符串
- 错误:函数"getLine"必须具有原型