我正在尝试使用 std::getline,但我的编译器告诉我 getline 未识别?
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <fstream>
#include <cstdlib>
int main(){
using namespace std;
string line;
ifstream ifile("test.in");
if(ifile.is_open()){
while(ifile.good()){
getline(ifile,line);
}
}
}
最佳答案
std::getline
在 string
中定义标题。
#include <string>
另外,您的代码没有使用 cstring
中的任何内容, cstdio
, cmath
, 或 cstdlib
;为什么要包括这些?
编辑:澄清关于 cstring
的混淆和 string
标题,cstring
提取C 运行时库的内容 string.h
进入std
命名空间; string
是C++ 标准库 的一部分,包含getline
, std::basic_string<>
(及其特化 std::string
和 std::wstring
)等——两个非常不同的标题。
关于c++ - std 没有成员 'getline' ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5781132/