C++的意外终止程序

发布于 01-22 09:56 字数 659 浏览 1 评论 0原文

我在以下程序中的错误是:它在执行中终止,甚至不允许用户输入输入。

#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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文