这是我的代码(C++)。这是为什么会崩溃?我如何解决它?
#include <iostream>
#include <fstream>
#include <cstdlib>
#include <sstream>
using namespace std;
void rotaryxorencrypt(int dat[],int len){
------------------------------
}
void encrypt(int dat[],int len){
rotaryxorencrypt(dat,len);
}
void decrypt(int dat[],int len){
}
int main() {
fstream file;
fstream *fileptr=&file;
file.open("tmp",ios::in);
string line;
string *lineptr=&line;
int x;
int *xptr=&x;
int cont=0;
int *contptr=&cont;
int len;
int *lenptr=&len;
stringstream ss;
stringstream *ssptr=&ss;
string cryption;
string *cryptionptr=&cryption;
getline(*fileptr,*lineptr);
try{
if(*lineptr=="encryption"){
*cryptionptr="encrypt";
}else if(*lineptr=="decrypt"){
*cryptionptr="decryption";
} else {
cout<<"Unknown Cryptography Type - "<<*lineptr<<endl;
throw 0;
}
getline(*fileptr,*lineptr);
*ssptr<<*lineptr;
*ssptr>>*xptr;
ss.str("");
ss.clear();
*lenptr=*xptr;
int *dataptr;
dataptr=new int[*lenptr];
cout<<"Loading Formatted Data"<<endl;
while (getline (*fileptr, *lineptr)) {
*ssptr<<*lineptr;
*ssptr>>*xptr;
ss.str("");
ss.clear();
dataptr[cont]=*xptr;
cont++;
}
file.close();
delete lineptr;
delete xptr;
delete contptr;
delete ssptr;
delete fileptr;
------------------
if(*cryptionptr=="encrypt"){
cout<<"Beginning Encryption Process."<<endl;
cout<<dataptr[0]<<endl;
encrypt(dataptr,len);
cout<<dataptr[0]<<endl;
cout<<"Outputting Encrypted Data."<<endl;
}else if(*cryptionptr=="decrypt"){
cout<<"Beginning Decryption Process."<<endl;
decrypt(dataptr,len);
cout<<"Outputting Decrypted Data."<<endl;
}
cout<<"Clearing Cache."<<endl;
delete []dataptr;
delete cryptionptr;
delete lenptr;
}catch(int x){
if(x==0){
cout<<"Clearing Cache."<<endl;
delete fileptr;
delete lineptr;
delete xptr;
delete contptr;
delete ssptr;
delete fileptr;
}else{
cout<<"Unknown Error - Cannot Clear The Cache."<<endl;
}
}
cout<<"here"<<endl;
return 0;
cout<<"here"<<endl;
}
注意cout<<"here"<<endl;
之前和之后return 0;
。没有他们我有同样的问题,所以他们不是问题,但它会执行第一个cout<<"here"<<endl;
,但会在第二个之前崩溃。如果我删除第二个,它会做同样的事情,如果我删除第一个,它就会崩溃,因此它崩溃在return 0;
。这是为什么发生。 (PS这是加密的另一个项目的一部分(可能敏感部分[不是崩溃点或代码错误]被转换为“-----------------”(这不是实际的代码)。
请做一个[mcve],如果你已经转储了100行,那么它就没有办法省略代码了,你的确切输出是什么? – Tas
你所描述的听起来不像是崩溃。感到惊讶的是,从你的主程序返回**返回结束你的程序? –
我确切的outp ut是(\ n表示有一个我无法输入的输入):加载格式化数据\ n开始加密过程。\ n140 \ n140 \ n输出加密数据。\ n清除缓存。\ n \ n(这是崩溃的地方)但其余的是在告诉windows(7)在调试模式下运行时关闭程序时打印的)\ n进程返回255(0xFF)执行时间:13.743 s \ n按任意键继续。 (结束输出)。为了给你剩下的代码,我忽略了在崩溃之前工作的任何代码,所以它不是问题,它也是敏感的(这是加密程序的一部分) – Justin