C++的意外终止程序
我在以下程序中的错误是:它在执行中终止,甚至不允许用户输入输入。
#include<iostream>
using namespace std;
class Graph
{
public:
char city;
int distance;
Graph *next;
};
Graph **graph=new Graph*[20];
int size;
void create()
{
cout<<"Enter the number of cities:";
cin>>size;
cout<<"Enter "<<size<<" cities\n";
for(int i=0;i<size;i++)
{
cout<<"City number "<<i+1<<":";
cin>>graph[i]->city;
cout<<endl;
}
}
int main()
{
create();
return 0;
}
输出语句甚至没有出现,并且程序将终止。请有人运行此代码并帮助我。这个问题以前从未发生过,因此我不知道如何解决这个问题。 先感谢您。
My error in the following program is: It terminates in the middle of execution and does not even allows user to enter the inputs.
#include<iostream>
using namespace std;
class Graph
{
public:
char city;
int distance;
Graph *next;
};
Graph **graph=new Graph*[20];
int size;
void create()
{
cout<<"Enter the number of cities:";
cin>>size;
cout<<"Enter "<<size<<" cities\n";
for(int i=0;i<size;i++)
{
cout<<"City number "<<i+1<<":";
cin>>graph[i]->city;
cout<<endl;
}
}
int main()
{
create();
return 0;
}
The output statements do not even appear and the program terminates. Please can someone run this code and help me out. This issue has never occurred before and so I do not know how to solve this.
Thank you in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论