首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C++ >

《C++ Primer Plus》,6-7,程序运行时卡住了解决方法

2012-06-20 
《C++ Primer Plus》,6-7,程序运行时卡住了题目来自《C++ Primer Plus》,编号6-7。编译环境为Microsoft Visual

《C++ Primer Plus》,6-7,程序运行时卡住了
题目来自《C++ Primer Plus》,编号6-7。编译环境为Microsoft Visual Studio C++ 2010

题目太长,就先不打了...不好意思(¯﹃¯),劳烦有条件的童鞋请自行拿书看下了。

C/C++ code
#include <iostream>#include <string>#include <cstring>#include <cctype>using namespace std;int main(){    struct donors    {        string name;        double donation;    };    int num;    cout << "enter the num plz";    cin >> num;    donors *p = new donors[num];    cout << "now enter data plz\n";    for (int i = 0;i < num;++i)    {        cin >> p[i].name;        cin >> p[i].donation;    }    cout << "Grand Patrons\n";    int count = 0;    for (int i = 0;i < num;++i)    {        if (p[i].donation > 10000)        {            cout << p[i].name << '\t' << p[i].donation << endl;            ++count;        }    }    if (count = 0)        cout << "none\n";    cout << "Patrons\n";    count = 0;    for (int i = 0;i < num;++i)    {        if (p[i].donation <= 10000)        {            cout << p[i].name << '\t' << p[i].donation << endl;            ++count;        }    }    if (count = 0)        cout << "none\n";    delete p;    return 0;}


正确地实现了题目的要求,但无论按什么都再没反应了,不知为啥。

[解决办法]
试试delete[] p;
使用单步调试很容易发现问题的,一定要学会调试自己的程序。

热点排行