(c++)在title.exe[6284]中出现fstream win32异常
(C++) fstream win32 exception occured in title.exe [6284]
所以我做了以下算法来解决一个问题,但我不明白为什么当我使用fstream而不是iostream时它会崩溃。当我使用较低的数字时,例如(输入例如:1 4 5),它与fstream完美地工作,但如果我使用一些较大的输入数字(例如:3 987654300 210),它会说"进程返回-1073741819 (0xC0000005)"。如果我使用iostream,即使是9位输入,它也能很好地工作。
是的,我有parola。In和parola。Out与.cpp/.exe在同一个文件夹中,in包含输入数字和所有内容。忽略算法和注释,只需注意"fout"answers"fin"的使用。
#include <fstream>
#include <iostream>
using namespace std;
int main()
{
ifstream fin("parola.in");
ofstream fout("parola.out");
int a,b,k; //VARIABILE ORIGINALE
int ord=1; //NUMARUL DE ORDINE AL VECTORILOR
int cifa=0,cifb=0; //NUMARUL DE CIFRE AL NUMERELOR A SI B
int nrA[18],nrB[10]; //VECTORII CE CONTIN CIFRELE NUMERELOR A SI B
int temp[9]; //VECTORUL CE CONTINE CIFRELE NR. A IN ORDINE INVERSA
fin>>k>>a>>b;
while (a>0)
{
temp[ord]=a%10;
a/=10;
ord++;
cifa++;
}
ord=1; //RESET NR ORDINE
while (b>0)
{
nrB[ord]=b%10;
b/=10;
ord++;
cifb++;
}
for (int topkek=1; topkek<=cifa; topkek++)
{
nrA[topkek]=temp[cifa+1-topkek]; //ORDONAREA CIFRELOR LUI A CRESCATOR, IN VECTORUL nrA
}
for (int zomtan=1; zomtan<=k; zomtan++)
{
fout<<nrA[zomtan];
nrA[zomtan]=-1;
}
fout<<nrB[1];
nrB[1]=-1;
for (int zomtan2=cifa+1; zomtan2<=18; zomtan2++)
{
nrA[zomtan2]=-1;
}
for (int zomtan3=cifb+1; zomtan3<=10; zomtan3++)
{
nrB[zomtan3]=-1;
}
for (ord=1; ord<=9; ord++)
{
if (nrA[ord+k]!=-1)
{
fout<<nrA[ord+k];
}
if (nrB[ord+1]!=-1)
{
fout<<nrB[ord+1];
}
}
return 0;
}
可能会出现问题,因为我认为,您使用基于1的数组而不是基于属性0的
for (int zomtan2=cifa+1; zomtan2<=18; zomtan2++)
{
nrA[zomtan2]=-1;
}
问题总是会发生,因为你写了zomtan2<=18
和你的数组声明是int nrA[18]
,我之前说过总是会导致问题。
这些错误在你的代码中无处不在,所以我建议你重写程序
相关文章:
- 处理多个异常集合的C++方法
- 我在c++代码中生成了一个运行时#3异常
- 孤立代码块在结构中引发异常
- C++中的赋值发生,尽管右侧出现异常
- 在fstream期间忽略空行
- 从构造函数抛出异常时如何克服内存泄漏
- 异常属于C++中的线程还是进程
- 当类定义不可见时捕获异常
- 引发异常:读取访问冲突**dynamicArray**为0x1118235.发生
- 为什么异常不退出程序?
- 为什么我应该在异常处理中使用std::cerr而不是std::cout
- 如何修复链表类实现的未处理异常0xDDDDDDDD
- 关于:C++中异常对象的范围:为什么我没有得到副本?
- 我是否应该期望在 CentOS6 和 CentOS7 之间处理 fstream 异常时有不同的行为
- 当"std::fstream"无法打开时会引发异常吗?
- 硬关闭控制台/C++ 后的 fstream 声明异常
- (c++)在title.exe[6284]中出现fstream win32异常
- fstream EOF异常抛出
- fstream打开时未处理异常
- c++ fstream:当到达eof时抛出异常