Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why am I getting this ifstream error?

Implicit instantiation of undefined template 'std::basic_ifstream<char,std::char_traits<char>>'


#ifndef MAPPER_H #define MAPPER_H #include <iostream> #include <string> #include <vector> #include "KeyValue.h" #include "Parser.h"  using namespace std; class Mapper { public:     Mapper(ifstream& infile);     ~Mapper(void);     void loadTokens();     void showTokens();     void map();     void printMap();     void printMap(string map_fileName); private:     ifstream inFile;  //<-- is where the error is happening     vector<string> tokens;     vector<KeyValue> map_output;     Parser* parser; };  #endif 

I've even tried putting std::ifstream and it still doesn't work.

When I #include <fstream> instead of #include <iostream>, I get these errors in fstream.tcc and basic_ios.tcc:

'operator=' is a private member of 'std::basic_streambuf<char>'

And since that's part of the fstream library, obviously something i'm doing is wrong...

Anyone able to help?

like image 456
OghmaOsiris Avatar asked Jan 25 '12 19:01

OghmaOsiris


People also ask

Why is ifstream not Opening file C++?

The issue is most likely one of the following: 1) map_2. txt does not exist in the location you specified in your ifstream declaration. 2) You do not have sufficient rights to access the root folder of your C drive.

What is ifstream in C++?

ifstream is an input file stream. It is a special kind of an istream that reads in data from a data file. ofstream is an output file stream. It is a special kind of ostream that writes data out to a data file.


1 Answers

You're missing

#include <fstream> 

and you probably assign somthing to inFile which is not allowed.

like image 108
Mika Fischer Avatar answered Sep 23 '22 02:09

Mika Fischer