| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 490 人关注过本帖
标题:编译出错,大家帮忙看看
只看楼主 加入收藏
zd123
Rank: 2
等 级:论坛游民
帖 子:43
专家分:33
注 册:2009-9-4
结帖率:70%
收藏
 问题点数:0 回复次数:2 
编译出错,大家帮忙看看

1>d:\竹林晚风\documents\visual studio 2008\projects\qqq\qqq\qqq.cpp(54) : error C2109: 下标要求数组或指针类型
1>d:\竹林晚风\documents\visual studio 2008\projects\qqq\qqq\qqq.cpp(54) : error C2228: “.output”的左边必须有类/结构/联合







#include "stdafx.h"
#include<iostream>
using namespace std;
class Book
{
private:
    char name[100];
    char num[20];
    char abstracts[100];
public:
    void input()
    {
        cout<<"Please input the name of the book:"<<endl;
        cin>>name;
        cout<<"Please input the num of the book:"<<endl;
        cin>>num;
        cout<<"Please input the abstract of the book:"<<endl;
        cin>>abstracts;
    }
    void output()
    {
        cout<<"The name of the book is :"<<name<<endl;
        cout<<"The num of the book is :"<<num<<endl;
        cout<<"The abstract of the book is :"<<abstracts<<endl;
    }
};
class Student
{
private:
    char name[100];
    char ID[50];
    Book a[5];
public:
    void inputs()
    {
        cout<<"Please input the name of the student :"<<endl;
        cin>>name;
        cout<<"Please input the ID of the student :"<<endl;
        cin>>ID;
    }
    void inputb(int i)
    {
        a[i].input();
    }
    void outputs (int a)
    {
        cout<<"The name of the student is :"<<name<<endl;
        cout<<"The ID of the student is:"<<ID<<endl;
        for (int j=0;j<a;j++)
        {
            a[j].output();
        }
    }
};



int _tmain(int argc, _TCHAR* argv[])
{
    Student stu;
    stu.inputs ();
    cout<<"Do you want to borrow a book?"<<endl;
    char s;
    cin>>s;
    int k=0;
    while (s=='Y'||s=='y')
    {
        
        stu.inputb(k);
        k++;
        if(k==5)
        {
            cout<<"you can't borrow a book more!"<<endl;
            break;
        }
    }
    cout<<"The massage you inputed are:"<<endl;
    stu.outputs (k);


    return 0;
}

搜索更多相关主题的帖子: 编译 
2009-12-02 23:04
debroa723
Rank: 10Rank: 10Rank: 10
等 级:贵宾
威 望:23
帖 子:862
专家分:1954
注 册:2008-10-12
收藏
得分:0 
void outputs (int a)
    {
        cout<<"The name of the student is :"<<name<<endl;
        cout<<"The ID of the student is:"<<ID<<endl;
        for (int j=0;j<a;j++)
        {
            a[j].output();//??????????????????
        }
    }
这个这个,是真的吗?
整形变量a被当做数组使用,真的不可以呀。
2009-12-17 22:30
bccnbin2009
Rank: 7Rank: 7Rank: 7
来 自:浙江
等 级:黑侠
帖 子:86
专家分:602
注 册:2009-10-5
收藏
得分:0 
void outputs (int a)
    {
        cout<<"The name of the student is :"<<name<<endl;
        cout<<"The ID of the student is:"<<ID<<endl;
        for (int j=0;j<a;j++)
        {
             a[j].output();
        }
    }
你把 “int a”中的a改成其他字母,比如k,

void outputs (int k)
    {
        cout<<"The name of the student is :"<<name<<endl;
        cout<<"The ID of the student is:"<<ID<<endl;
        for (int j=0;j<k;j++)
        {
             a[j].output();
        }
    }

这样就可以了,因为对象数组名也是a,与参数a同名了,c++会报错的。

滨封千里
2009-12-18 16:35
快速回复:编译出错,大家帮忙看看
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.025743 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved