| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 582 人关注过本帖
标题:结构成员的读取问题
取消只看楼主 加入收藏
caochuan2000
Rank: 2
等 级:论坛游民
帖 子:66
专家分:35
注 册:2009-4-11
结帖率:76.47%
收藏
 问题点数:0 回复次数:4 
结构成员的读取问题
帮忙看下我的程序哪有问题:
#include <iostream>
#include <string>
int main()
{
    using namespace std;
    struct car
    {
        string mader;
        int year;
    };
    car *ps=new car;
    int number;
    cout<<"How many cars do you wish to catalog:";
    cin>>number;
    for(int i=0;i<number;i++)
    {
        cout<<"\nCar #"<<i<<":"<<endl;
        cout<<"Please enter the make:";
        cin.get(*(ps+i).mader);
        cout<<"please enter the year made:";
        cin>>*(ps+i).year;
    }
    cout<<"Here is your collection:"<<endl;
    for(int i=0;i<number;i++)
        cout<<*(p+i).year cout<< *(p+i).mader<<endl;
}

编译出现:
error C2228: left of '.mader' must have class/struct/union type
error C2228: left of '.year' must have class/struct/union type
搜索更多相关主题的帖子: 成员 结构 
2010-06-16 16:14
caochuan2000
Rank: 2
等 级:论坛游民
帖 子:66
专家分:35
注 册:2009-4-11
收藏
得分:0 
有知道的请帮忙看看,谢谢了啊
2010-06-16 18:13
caochuan2000
Rank: 2
等 级:论坛游民
帖 子:66
专家分:35
注 册:2009-4-11
收藏
得分:0 
我改了还是编译不了啊,后面的P,写错了,是PS
2010-06-17 08:33
caochuan2000
Rank: 2
等 级:论坛游民
帖 子:66
专家分:35
注 册:2009-4-11
收藏
得分:0 
改动后的程序:
#include <iostream>
#include <string>
int main()
{
    using namespace std;
    struct car
    {
        string mader;
        int year;
    };
    int number;
    cout<<"How many cars do you wish to catalog:";
    cin>>number;
    car *ps=new car[number];
    for(int i=0;i<number;i++)
    {
        cout<<"\nCar #"<<i<<":"<<endl;
        cout<<"Please enter the make:";
        cin.get(*(ps+i).mader);
        cout<<"please enter the year made:";
        cin>>*(ps+i).year;
    }
    cout<<"Here is your collection:"<<endl;
    for(int i=0;i<number;i++)
        cout<<*(ps+i).year cout<< *(ps+i).mader<<endl;
}
2010-06-17 08:33
caochuan2000
Rank: 2
等 级:论坛游民
帖 子:66
专家分:35
注 册:2009-4-11
收藏
得分:0 
6楼的什么意思啊?这句有错吗?
2010-06-17 09:56
快速回复:结构成员的读取问题
数据加载中...
 
   



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

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