In this example code, <fstream>
works fine but <string>
doesn't: (errors in comments)
#include <iostream>
#include <fstream>
#include <string>
int main(){
using namespace std;
string line; //incomplete type is not allowed
ifstream ifile("test.in");
if(ifile.is_open()){
while(ifile.good()){
getline(ifile,line); //identifier "getline" is undefined
}
}
}
The error of getline()
becomes "namespace "std" has no member "getline"" when I change the code to:
int main(){
std::string line; //incomplete type is not allowed
std::ifstream ifile("test.in");
if(ifile.is_open()){
while(ifile.good()){
std::getline(ifile,line); //namespace "std" has no member "getline"
}
}
}
This code "fixes" the error of the declaration of string line
:
std::string* line;
or also:
using namespace std;
string* line;