【问题标题】:Why am I getting this ifstream error?为什么我会收到此 ifstream 错误?
【发布时间】:2012-02-19 00:26:10
【问题描述】:

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

我什至试过输入std::ifstream,但还是不行。

当我#include &lt;fstream&gt; 而不是#include &lt;iostream&gt; 时,我在fstream.tccbasic_ios.tcc 中收到这些错误:

'operator=' is a private member of 'std::basic_streambuf&lt;char&gt;'

由于这是 fstream 库的一部分,显然我做的事情是错误的......

有人可以帮忙吗?

【问题讨论】:

  • 你应该有&lt;fstream&gt; 而不是&lt;iostream&gt; operator= 是真正的错误。输出窗口应该包含该错误消息的其余部分,包括复制Mapper 对象的行号。
  • 你需要显示导致第二个错误的代码。

标签: c++ compiler-errors fstream ifstream


【解决方案1】:

你不见了

#include <fstream>

您可能会将某些东西分配给inFile,这是不允许的。

【讨论】:

  • 由于某种原因,我的问题删掉了我已经导入 fstream 的部分
  • 您可以编辑它。这将有助于提供一个其他人可以尝试编译的最小示例。
  • 我认为ifstream 包含在&lt;iostream&gt; 中,直到我膝盖中了一箭。
猜你喜欢
  • 2018-06-22
  • 2016-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-02-24
  • 1970-01-01
相关资源
最近更新 更多