ifstream初始化错误 - 错误读取字符

时间:2016-01-28 08:19:40

标签: c++ ifstream

    #include "Stdafx.h"
    #include "FishTracker.h"
    #include <string>
    #include "Utils.h"
    #include <fstream>

    using namespace std;
    using namespace cv;
    int main()
    {
        std::string videopath;
        videopath = "E:\\TUKLNUST\\fishdata2\\Damo\\AR2-6\\Tetraodontidae_Lagocephalus_sceleratus_AD\\00001\\";

        ifstream str;
        str.open((videopath + DATA_TXT).c_str());
        if (str.is_open())
        {
            cout << "file is open.";
        }
    }

文件已打开,但str就是这个。

+       str {_Filebuffer={_Set_eback=0xcccccccc <Error reading characters of string.> _Set_egptr=0xcccccccc <Error reading characters of string.> ...} }    std::basic_ifstream<char,std::char_traits<char> >

CONFIGS
win32,Debug
Visual Studio 2013

1 个答案:

答案 0 :(得分:0)

#include "Stdafx.h"
#include "FishTracker.h"
#include <string>
#include "Utils.h"
#include <fstream>

using namespace std;
using namespace cv;
int main()
{
    std::string videopath;
        videopath = "E:\\TUKLNUST\\fishdata2\\Damo\\AR2-6\\Tetraodontidae_Lagocephalus_sceleratus_AD\\00001\\";

        ifstream str;
        str.open((videopath + "DATA_TXT").c_str());
        if (str.is_open())
    {
        cout << "file is open.";
    }

}