I’m trying to use std::getline, but my compiler is telling me that getline isn’t identified?
#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::getlineis defined in thestringheader.Also, your code isn’t using anything from
cstring,cstdio,cmath, orcstdlib; why bother including these?EDIT: To clarify the confusion regarding the
cstringandstringheaders,cstringpulls the contents of the C runtime library’sstring.hinto thestdnamespace;stringis part of the C++ standard library and containsgetline,std::basic_string<>(and its specializationsstd::stringandstd::wstring), etc. — two very different headers.