C++ 为什么我会收到这个 ifstream 错误?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/9009169/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Why am I getting this ifstream error?
提问by OghmaOsiris
Implicit instantiation of undefined template 'std::basic_ifstream<char,std::char_traits<char>>'
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.
我什至尝试过放置std::ifstream
,但它仍然不起作用。
When I #include <fstream>
instead of #include <iostream>
, I get these errors in fstream.tcc
and basic_ios.tcc
:
当我#include <fstream>
代替 时#include <iostream>
,我在fstream.tcc
and 中收到这些错误basic_ios.tcc
:
'operator=' is a private member of 'std::basic_streambuf<char>'
'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...
由于那是 fstream 库的一部分,显然我所做的事情是错误的......
Anyone able to help?
任何人都可以提供帮助?
回答by Mika Fischer
You're missing
你不见了
#include <fstream>
and you probably assign somthing to inFile
which is not allowed.
你可能分配了inFile
一些不允许的东西。