C ++进程终止于状态-1073741510(0分钟,2秒) [英] C++ Process terminated with status -1073741510 (0 minute(s), 2 second(s))

查看:6341
本文介绍了C ++进程终止于状态-1073741510(0分钟,2秒)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

执行exe后,我收到此错误:



进程以状态-1073741510(0分钟,2秒)终止



我应该为long变量设置一个限制吗?我在编译后收到0条警告



以下是代码:

  #include< iostream> 
#include< fstream>
//#define long long 100000000;
//#define int 1000;

using namespace std;
void test1();
void test2();
void test3();
int main()
{
int p,n;
// long z;
long sir [2 * n];
std :: ifstream file;
file.open(input.txt);
文件>> p;
file>> n;
for(int i = 0; i <(2 * n); i ++){
file>> sir [i];
}
file.close();
if(p == 1)test1();
else if(p == 2)test2();
else test3();
return 0;
}
void test1(){
cout<< 1; // sir [2];
}
void test2(){
cout<< d;
}
void test3(){
cout<< d;
}


解决方案

$ c> n 之前使用 long sir [2 * n]; 。这个测量你使用一个垃圾大小声明数组,所以现在你有一个垃圾数组。



由于 long sir [2 * n];

code>是一个可变长度数组,不是标准的我建议您使用 std :: vector ,并在从文件中读取它后设置它的大小。像下面这样应该工作

  file.open(input.txt); 
文件>> p;
file>> n;
std :: vector< long> sir(n);

如果不能使用向量,那么你可以使用一个指针并创建 $ >

$ );
file>> p;
file>> n;
long * sir = new long [2 * n];

你必须记住使用 delete [] sir; 你完成后,你会得到一个内存泄漏。


After I execute the exe I get this error :

Process terminated with status -1073741510 (0 minute(s), 2 second(s))

Should I set a limit to long variables ? I get 0 warnings after compiling

Here is the code :

#include <iostream>
#include <fstream>
//#define long long 100000000;
//#define int 1000;

using namespace std;
void test1();
void test2();
void test3();
int main()
{
    int p,n;
   // long z;
    long sir[2*n] ;
    std::ifstream file;
    file.open("input.txt");
    file >> p;
    file >>n;
    for (int i=0;i< (2*n);i++){
        file >> sir[i];
    }
    file.close();
    if (p==1)test1();
    else if(p==2)test2();
    else test3();
    return 0;
}
void test1(){
    cout << 1;//sir[2];
}
void test2(){
    cout << "d";
}
void test3(){
    cout << "d";
}

解决方案

You never initialized n before you used in long sir[2*n] ;. This meas you use a garbage size do declare the array so now you have a garbage array. Any use of that array is going to be undefined behavior and the cause of your problem.

Since long sir[2*n] ; is a variable length array and not standard I suggest you use a std::vector and set its size after you read it in from the file. Something like the following should work

file.open("input.txt");
file >> p;
file >>n;
std::vector<long> sir(n);

If you can't use a vector then you can you a pointer and create the array with new after you read the size like

file.open("input.txt");
file >> p;
file >>n;
long * sir = new long[2*n];

You do have to remember to use delete [] sir; after you are done with it so you do get a memory leak.

这篇关于C ++进程终止于状态-1073741510(0分钟,2秒)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆