首页 > 代码库 > practice4_stack_struct

practice4_stack_struct

 

\documents\visual studio 2008\projects\practice4_stack\practice4_stack\practice4_stack.cpp(22) : error C2628: “BankLevel
”后面接“void”是非法的(是否忘记了“;”?)

这个提示第一次看起来比较突兀,实际上检查下BankLevel结构体的定义结束的地方是否加了分号!!

 

// Practice4_stack.cpp : 定义控制台应用程序的入口点。
//

#include "stdafx.h"
#include <stack>
#include <iostream>
#include <algorithm>
#include <stdlib.h>
#include <time.h>
#include <string>

using namespace std;//一定不要忘记这句

string strs[5] = {"zhonghang", "gonghang", "nonghang", "jianhang", "jiaohang"};

struct BankLevel
{
    string name;
    unsigned int level;
}; /* 开始这里少写一个分号,导致编译不过,教训!!*/

void initStack(stack<BankLevel> &ss, unsigned int size)
{
    unsigned int num = 0;
    srand(unsigned(time(0)));
    for(unsigned int i = 0; i < size; i++)
    {
        num = rand()%100;
        BankLevel blevel = {strs[i], num};
        ss.push(blevel);
    }
}

int _tmain(int argc, _TCHAR* argv[])
{
    stack<BankLevel> ss;
    initStack(ss, 5);

    while(!ss.empty())
    {
        cout << ss.top().name << "," << ss.top().level << endl;
        ss.pop();
    }
    return 0;
}

 

按Ctrl+F5调试:

jiaohang,93
jianhang,17
nonghang,60
gonghang,67
zhonghang,67

 

结构体定义结束未加分号(不止一个人遇到,可以写到C陷阱里去了!!):

http://tieba.baidu.com/p/2028664203

http://blog.csdn.net/mocha_lucy/article/details/46427285

practice4_stack_struct