| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 290 人关注过本帖
标题:为何我这个会出错?
只看楼主 加入收藏
w273732573
Rank: 1
等 级:新手上路
帖 子:6
专家分:5
注 册:2008-5-28
收藏
 问题点数:0 回复次数:0 
为何我这个会出错?
#include<iostream>
#include<iomanip>
#include<cstdio>
#include<cstdlib>
#define k 2
using namespace std;
int main()
{
        struct abc
        {
                char name[20];
                int age;
        }*s,*s1;
        int j;
        s=new struct abc[k];
        if(s==NULL) abort();
        s1=s;
        cout<<"*s=\n";
        for(j=0;j<=k-1;j++)
        {
                cin>>s->name>>s->age;
                cout<<s->name<<" "<<s->age<<"\n";
                s++;
        }
    delete s1;
        char a[3][10],*p[3];
        int i;
        for(i=0;i<=2;i++)
                p[i]=a[i];
        for(i=0;i<=2;i++)
        {
                cout<<"a["<<i<<"]=";
                gets(p[i]);
        }
        cout<<endl;
        for(i=0;i<=2;i++)
        {
                puts(a[i]);
                puts(p[i]);
                cout<<"a["<<i<<"]="<<a[i]<<endl;
                cout<<"p["<<i<<"]="<<p[i]<<endl;
                cout<<"&a["<<i<<"]="<<&a[i]<<endl;
                cout<<"&p["<<i<<"]="<<&p[i]<<endl;
                printf("%.3s\n",p[i]);
                cout<<*(a+i)+2<<endl;
        }
        return 0;
}
               
本来我单独写下面一段没错,后来又新做了一题写了
        struct abc
        {
                char name[20];
                int age;
        }*s,*s1;
        int j;
        s=new struct abc[k];
        if(s==NULL) abort();
        s1=s;
        cout<<"*s=\n";
        for(j=0;j<=k-1;j++)
        {
                cin>>s->name>>s->age;
                cout<<s->name<<" "<<s->age<<"\n";
                s++;
        }
    delete s1;
这一段,好像这段和后面的没有什么影响 ,可是为什么下面那段的程序受到影响出错了呢?
搜索更多相关主题的帖子: include 
2009-10-17 19:57
快速回复:为何我这个会出错?
数据加载中...
 
   



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

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