C++状态-1073741676
C++ status -1073741676
我在网上做了一些调查,但没有找到 Code::Blocks 显示的错误代码 -1073741676
的解释。
准确的错误信息是Process terminated with status -1073741676 (0 minute(s), 8 second(s))
。
对于这种精确状态是否有一个全局的、恒定的解释,或者它是否随着编译器、IDE 或任何其他变量而改变?
代码(尽我所能):
main.cpp
int n(0), choix(0);
string dis;
// Nobel* laureats = saisie(n); // Saisie à la main
Nobel* laureats = lecture(n);
cin >> dis;
cout << agemoyen(laureats, n, dis) << endl;
Nobel.h
#ifndef NOBEL_H_INCLUDED
#define NOBEL_H_INCLUDED
#include <string>
struct Nobel
{
std::string nom, discipline;
int annee, age;
std::string pays;
};
int agemoyen(Nobel* NO, int n, std::string dis);
Nobel* lecture(int& n);
#endif // NOBEL_H_INCLUDED
Nobel.cpp
int agemoyen(Nobel* NO, int n, string dis){
int ages(0);
int total(0);
for(int i = 0 ; i < n ; i++){
if(NO[i].discipline == dis){
ages += NO[i].age;
total++;
}
}
ages /= total;
return ages;
}
Nobel* lecture(int& n){
Nobel* laureats;
ifstream fichier("tp7nobel.txt", ios::in);
if (fichier.is_open()) {
fichier >> n;
cout << n << endl;
laureats = new Nobel[n];
for(int i = 0 ; i < n; i++){
fichier >> laureats[i].nom >> laureats[i].discipline >> laureats[i].annee >> laureats[i].age >> laureats[i].pays;
cout << i << ")" << laureats[i]. nom << endl;
}
fichier.close();
}else{
cerr << "Impossible d'ouvrir ce fichier." << endl;
}
return laureats;
}
-1073741676 是十六进制值 0xC0000094 - Windows
上的整数除以零异常代码
代码:c0000094
说明:EXCEPTION_INT_DIVIDE_BY_ZERO
更新
我想你必须在使用它之前检查 total
是否不为零:
if (total) {
ages /= total;
}
我在网上做了一些调查,但没有找到 Code::Blocks 显示的错误代码 -1073741676
的解释。
准确的错误信息是Process terminated with status -1073741676 (0 minute(s), 8 second(s))
。
对于这种精确状态是否有一个全局的、恒定的解释,或者它是否随着编译器、IDE 或任何其他变量而改变?
代码(尽我所能):
main.cpp
int n(0), choix(0);
string dis;
// Nobel* laureats = saisie(n); // Saisie à la main
Nobel* laureats = lecture(n);
cin >> dis;
cout << agemoyen(laureats, n, dis) << endl;
Nobel.h
#ifndef NOBEL_H_INCLUDED
#define NOBEL_H_INCLUDED
#include <string>
struct Nobel
{
std::string nom, discipline;
int annee, age;
std::string pays;
};
int agemoyen(Nobel* NO, int n, std::string dis);
Nobel* lecture(int& n);
#endif // NOBEL_H_INCLUDED
Nobel.cpp
int agemoyen(Nobel* NO, int n, string dis){
int ages(0);
int total(0);
for(int i = 0 ; i < n ; i++){
if(NO[i].discipline == dis){
ages += NO[i].age;
total++;
}
}
ages /= total;
return ages;
}
Nobel* lecture(int& n){
Nobel* laureats;
ifstream fichier("tp7nobel.txt", ios::in);
if (fichier.is_open()) {
fichier >> n;
cout << n << endl;
laureats = new Nobel[n];
for(int i = 0 ; i < n; i++){
fichier >> laureats[i].nom >> laureats[i].discipline >> laureats[i].annee >> laureats[i].age >> laureats[i].pays;
cout << i << ")" << laureats[i]. nom << endl;
}
fichier.close();
}else{
cerr << "Impossible d'ouvrir ce fichier." << endl;
}
return laureats;
}
-1073741676 是十六进制值 0xC0000094 - Windows
上的整数除以零异常代码代码:c0000094
说明:EXCEPTION_INT_DIVIDE_BY_ZERO
更新
我想你必须在使用它之前检查 total
是否不为零:
if (total) {
ages /= total;
}