【问题标题】:ifstream initialization error- Error Reading Charactersifstream 初始化错误 - 读取字符时出错
【发布时间】:2016-01-28 08:19:39
【问题描述】:
    #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> >

配置:
win32,调试
Visual Studio 2013

【问题讨论】:

  • 你不能在函数之外使用这些语句。
  • 是的,我在 main 中使用它们
  • 请贴出真实代码!
  • 也发布一个真正的问题!说真的,请去研究发布指南,那里解释了您在问题中做错的许多事情。

标签: c++ ifstream


【解决方案1】:
#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.";
    }

}

【讨论】:

  • @OmerJR,我添加了 "DATA_TXT",你只是把它当作一个变量。
  • 我在 FishTracker.h 中定义为#define DATA_TXT "Data.txt"
猜你喜欢
  • 1970-01-01
  • 2016-09-20
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-02-12
  • 2022-01-25
  • 2018-12-16
相关资源
最近更新 更多