Answer the question
In order to leave comments, you need to log in
How to fix error while reading file in c++?
When opening a file with wifstream, the program crashes and gives this error. The txt file exists and the path to it is correct. Maybe someone had a similar problem?
main function code:
#include "stdafx.h"
int _tmain(int argc, _TCHAR* argv[])
{
//setlocale(LC_ALL, "rus");
wifstream nja(L"text1.txt");
if (!nja.is_open())
cout<<"Ошибка!";
Parm::PARM parm;
cout << argc;
cout << "---- Тест Error::geterror ---" << endl << endl;
try { ERROR_THROW(104); }
catch (Error::ERROR e)
{
cout << "Ошибка " << e.id << ": " << e.message << endl << endl;
};
cout << "---- Тест Error::geterrorin ---" << endl << endl;
try { ERROR_THROW_IN(111, 7, 7); }
catch (Error::ERROR e)
{
cout << "Ошибка " << e.id << ": " << e.message
<< ", строка " << e.inext.line
<< ", позиция " << e.inext.col << endl << endl;
};
cout << "---- Тест Parm::getparm ---" << endl << endl;
try
{
parm = Parm::getparm(argc, argv);
wcout << L"-in:" << parm.in << L", -out:" << parm.out << L", -log:" << parm.log << endl << endl;
}
catch (Error::ERROR e)
{
cout << "Ошибка " << e.id << ": " << e.message << endl << endl;
};
cout << "---- Тест Parm::getin ---" << endl << endl;
try
{
In::IN in = In::getin(parm.in);
cout << in.text << endl;
cout << "Всего символов: " << in.size << endl;
cout << "Всего строк: " << in.lines << endl;
cout << "Пропущено: " << in.ignor << endl;
}
catch (Error::ERROR e)
{
cout << "Ошибка " << e.id << ": " << e.message << endl << endl;
};
system("pause");
return 0;
}
Содержимое stdafx.h:
#pragma once
#include "targetver.h"
#include <fstream>
#include <iostream>
#include <tchar.h>
#include <stdio.h>
#include <cwchar>
#include <stdio.h>
#include <cstring>
#include <wchar.h>
#include <locale>
#include "Error.h"
#include "Parm.h"
#include "In.h"
using namespace std;
Answer the question
In order to leave comments, you need to log in
Show the call stack. Now you are looking at the STL source, it is unlikely that the error is in it, most likely you are calling the standard function crookedly. Would love to see the stack and how you call the first library function on that stack.
There is a high probability that the error is in mods[mode]. Fourteen values written as 4+4+3+3 is something strange. You obviously wanted to make a “dice” of four flags, from the youngest to the oldest - W, A (and it works like a simple W if A is without W), B, RW
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question