【问题标题】:error C2039: 'Open' : is not a member of 'std::basic_fstream错误 C2039:“打开”:不是“std::basic_fstream”的成员
【发布时间】:2011-10-16 08:27:29
【问题描述】:

当我打电话时

void fileOpen(const char*
 fname_){file_.Open(fname_,ios::in|ios::out|ios::ate|ios::binary);};

类似的功能 tempobj->fileOpen("LastID.dat");

它给了我错误

Error   23  error C2039: 'Open' : is not a member of 'std::basic_fstream<_Elem,_Traits>'

我该如何解决这个问题。这是我有这个功能的类。是模板类

#ifndef FileHandlerh_h
#define FileHandlerh_h
#include <iostream>
#include <cstdlib>
#include <fstream>

using namespace std;
template <class T>
class FileHandler
{
    private:
        fstream file_;


    public:
        FileHandler(){};

        FileHandler(const char* fname_){fileOpen(fname_);};

        void fileOpen(const char* fname_){file_.Open(fname_,ios::in|ios::out|ios::ate|ios::binary);};

        void fileWrite(T);
        void fileSeekWrite(T,int);
        T fileRead(int);
        int getNoOfRecords();

        ~FileHandler(){file_.close();};

};

帮我解决这个...!!

【问题讨论】:

  • 只看错误信息'Open' : is not a member of 'std::basic_fstream&lt;_Elem,_Traits&gt;'

标签: c++ templates visual-c++ compiler-errors


【解决方案1】:

C++ 区分大小写。您需要使用open() 而不是Open()

【讨论】:

  • 和 38 个 SO 用户的时间。将您的问题标记为已回答,以结束您的问题。
【解决方案2】:

也许使用小写的O?在标准库中的函数名中看到大写字母是很不常见的。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-07-26
    • 1970-01-01
    • 2016-03-08
    • 1970-01-01
    • 2019-11-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多