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::getline
is defined in the string
header.
#include <string>
Also, your code isn't using anything from cstring
, cstdio
, cmath
, or cstdlib
; why bother including these?
EDIT: To clarify the confusion regarding the cstring
and string
headers, cstring
pulls the contents of the C runtime library's string.h
into the std
namespace; string
is part of the C++ standard library and contains getline
, std::basic_string<>
(and its specializations std::string
and std::wstring
), etc. -- two very different headers.