标题:结构体,数组,指针在一块怎么写
只看楼主
zhshh
Rank: 1
等 级:新手上路
帖 子:2
专家分:0
注 册:2017-9-17
 问题点数:0 回复次数:1 
结构体,数组,指针在一块怎么写
程序代码:
#include <iostream>
#include<string>
using namespace std;
struct student {
    long number;
    string name;
    char sex;
    int score;
};
main()
{
    int i;
    student stu[50];
    student* p;

    //for (i=1; i<=3; i++) {
    //    cin>>stu[i].name;
    //    stu[i].number=i;
    //    cin>>stu[i].score;
    //}
    //for (i=1; i<=3; i++) {
    //    cout.width(20);
    //    cout<<stu[i].name;
    //    cout.width(10);
    //    cout<<stu[i].score;
    //    cout<<endl;
    //}
    p=&stu[1];
    for (i=1; 1<=3; i++) {
        p+=1;
        cin>>p->name;
        p->number=i+3;
        cin>>p->score;
        cout<<i;
    }
    for (i=1; i<=3; i++) {
        cout.width(20);
        cout<<stu[i].name;
        cout.width(10);
        cout<<stu[i].score;
        cout<<endl;
    }
    return 0;
}

上面第三个for(没有注释的第一个for)运行时i从1一直到了N,不在i<=3还是运行
如图
开始注释掉的句子是最开始可以用的,因为正在学c++,尽可能的用复杂些,然后就出错了。。。
搜索更多相关主题的帖子: name stu score for cout 
2017-09-17 09:41
zhshh
Rank: 1
等 级:新手上路
帖 子:2
专家分:0
注 册:2017-9-17
得分:0 
不小心把i和1弄混了。。没有开代码高亮等等
2017-09-17 09:56



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-480762-1-1.html




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

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