C++ | Q:执行可执行文件时出现cygwin异常|
C++ | Q: cygwin exception when executing the executable |
下面我写了一个简单的例子来演示我遇到的问题。执行代码后,我得到一个 cygwin 异常 7200。我环顾四周并尝试了一些事情,但没有解决。有人可以解释为什么我得到它,我该如何解决?感谢您的宝贵时间,在此先致谢!
代码
#include <string>
#include <vector>
// string
using std::string;
// vector
using std::vector;
class Person{
private:
string name;
int age;
public:
Person(string& name, int& age);
};
Person::Person(string& name, int& age): name(name), age(age){}
int main(){
vector<Person> people;
string* names = new string[3];
names[0] = "bob";
names[1] = "alice";
names[2] = "hank";
int* ages = new int[3];
ages[0] = 10;
ages[1] = 20;
ages[2] = 30;
for(unsigned int i = 0; i < 3; ++i){
Person person(names[i], ages[i]);
people.push_back(person);
}
delete names;
delete ages;
return 0;
}
错误
0 [main] a 7200 cygwin_exception::open_stackdumpfile: Dumping stack
trace to a.exe.stackdump
P.S - 我对 C++ 比较陌生。
您需要删除 delete[]
而不是 delete
的数组。
delete[] names;
delete[] ages;
下面我写了一个简单的例子来演示我遇到的问题。执行代码后,我得到一个 cygwin 异常 7200。我环顾四周并尝试了一些事情,但没有解决。有人可以解释为什么我得到它,我该如何解决?感谢您的宝贵时间,在此先致谢!
代码
#include <string>
#include <vector>
// string
using std::string;
// vector
using std::vector;
class Person{
private:
string name;
int age;
public:
Person(string& name, int& age);
};
Person::Person(string& name, int& age): name(name), age(age){}
int main(){
vector<Person> people;
string* names = new string[3];
names[0] = "bob";
names[1] = "alice";
names[2] = "hank";
int* ages = new int[3];
ages[0] = 10;
ages[1] = 20;
ages[2] = 30;
for(unsigned int i = 0; i < 3; ++i){
Person person(names[i], ages[i]);
people.push_back(person);
}
delete names;
delete ages;
return 0;
}
错误
0 [main] a 7200 cygwin_exception::open_stackdumpfile: Dumping stack trace to a.exe.stackdump
P.S - 我对 C++ 比较陌生。
您需要删除 delete[]
而不是 delete
的数组。
delete[] names;
delete[] ages;