24小时热门版块排行榜    

查看: 1082  |  回复: 7
本帖产生 1 个 程序强帖 ,点击这里进行查看

zyj8119

木虫 (著名写手)

[交流] 【求助】一个程序,不同编译器结果不同【已完结】已有2人参与

CODE:
#include
#include
struct STRU
{     char s1[5],s2[5];
      int a,b;
};

char *str_num(int n)
{    int k=0,m=n,i=0;
     while(m){k++;m/=10;}
         char *str=new char[k+1];
         while(n){
                 str[k-i-1]=n%10+'0';
                 n/=10;i++;
         }
         str[i]='\0';
         return str;
}

char *fun(STRU *p1,int n)
{   int k=0;
    for(int i=0;i                 k+=strlen(p1[i].s1)+strlen(p1[i].s2);
                int t1=p1[i].a,t2=p1[i].b;
                while(t1){k++;t1/=10;}
                while(t2){k++;t2/=10;}
        }
        char *p2=new char[k+1];
        strcpy(p2," ");
        for(i=0;i                 strcat(p2,p1[i].s1);
                strcat(p2,p1[i].s2);
                char *temp=str_num(p1[i].a);
                strcat(p2,temp);
                delete []temp;
                temp=str_num(p1[i].b);
                strcat(p2,temp);
                delete []temp;
                temp=0;
        }
        return p2;
}

void main()
{    STRU st[2]={"AAA","BBB",234,1535,"CCCC","DDDD",9559,453};
     char *p=fun(st,2);
         cout<          delete []p;
}

这个程序用VC编译没问题,但是用mingw develop studio编译出现以下错误:
In file included from C:\MinGWStudio\MinGW\include\c++\3.3.1\backward\iostream.h:31,
from ggg.cpp:1:
C:\MinGWStudio\MinGW\include\c++\3.3.1\backward\backward_warning.h:32:2: warning: #warning This file includes at least one deprecated or antiquated header. Please consider using one of the 32 headers found in section 17.4.1.2 of the C++ standard. Examples include substituting the header for the header for C++ includes, or instead of the deprecated header . To disable this warning use -Wno-deprecated.
ggg.cpp: In function `char* fun(STRU*, int)':
ggg.cpp:30: error: name lookup of `i' changed for new ISO `for' scoping
ggg.cpp:22: error:   using obsolete binding at `i'
ggg.cpp: At global scope:
ggg.cpp:45: error: `main' must return `int'
ggg.cpp:45: error: return type for `main' changed to `int'

ggg.o - 4 error(s), 1 warning(s)

[ Last edited by nono2009 on 2010-11-11 at 07:31 ]
回复此楼
好好学习,天天向上。
已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖

gd88

金虫 (小有名气)


zyj8119(金币+10):谢谢您精彩的回复!!!! 2010-11-03 07:21:37
nono2009(金币+1, 程序强帖+1):鼓励应助 2010-11-11 07:31:20
从目前的编译信息来看:
warning: #warning This file includes at least one deprecated or antiquated header.
你这段代码包含了不赞成的或者是老标准的文件头,

Please consider using one of the 32 headers found in section 17.4.1.2 of the C++ standard.
参看 C++ Standard 的 17.4.1.2 (我看了,里面没有 .h )

Examples include substituting the header for the header for C++ includes, or instead of the deprecated header .
用<******>代替<******.h>(把.h去掉),
或者用代替

To disable this warning use -Wno-deprecated.

编译器版本的问题,目前的信息看来。
根据编译的信息作修改先,不行的话去看 C++ standard 的 17.4.1.2 部分的内容。
再不行的话,帖出编译信息。

---------------------------另:
刚才我在虚拟机里装了个WinGW 2.05,
重现了你的代码错误,
C:\MinGWStudio\MinGW\include\c++\3.3.1\backward\backward_warning.h:32:2: warning: #warning This file includes at least one deprecated or antiquated header. Please consider using one of the 32 headers found in section 17.4.1.2 of the C++ standard. Examples include substituting the header for the header for C++ includes, or instead of the deprecated header . To disable this warning use -Wno-deprecated.

去掉     .h     后,
反正上面重现的这段编译错误没有了。

-----------------------------
哎,查了查,试了试,
编译器的问题,或者说标准的问题。
你试下这段代码把,我这里仅仅是编译通过了。  revised    是修改的地方。
为什么这么修改,我也是根据你的编译信息,google了一下而已。
要符合你的程序需求,可能还要调一下。

编译器之间的问题还是要重视的。
CODE:
#include /*revised*/
#include /*revised*/
struct STRU
{     char s1[5],s2[5];
      int a,b;
};

char *str_num(int n)
{    int k=0,m=n,i=0;
     while(m){k++;m/=10;}
         char *str=new char[k+1];
         while(n){
                 str[k-i-1]=n%10+'0';
                 n/=10;i++;
         }
         str[i]='\0';
         return str;
}

char *fun(STRU *p1,int n)
{   int k=0;
    for(int i=0;i                 k+=strlen(p1[i].s1)+strlen(p1[i].s2);
                int t1=p1[i].a,t2=p1[i].b;
                while(t1){k++;t1/=10;}
                while(t2){k++;t2/=10;}
        }
        char *p2=new char[k+1];
        strcpy(p2," ");
        for(int i=0;i                 strcat(p2,p1[i].s1);
                strcat(p2,p1[i].s2);
                char *temp=str_num(p1[i].a);
                strcat(p2,temp);
                delete []temp;
                temp=str_num(p1[i].b);
                strcat(p2,temp);
                delete []temp;
                temp=0;
        }
        return p2;
}

int main() /*revised*/
{    STRU st[2]={"AAA","BBB",234,1535,"CCCC","DDDD",9559,453};
     char *p=fun(st,2);
         std::cout<          delete []p;
         return 0; /*revised*/
}

[ Last edited by gd88 on 2010-11-3 at 04:47 ]
2楼2010-11-03 03:05:06
已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖

zyj8119

木虫 (著名写手)

引用回帖:
Originally posted by gd88 at 2010-11-03 03:05:06:
从目前的编译信息来看:
warning: #warning This file includes at least one deprecated or antiquated header.
你这段代码包含了不赞成的或者是老标准的文件头,

Please consider using one of the 32 he ...

非常感谢!!!!
好好学习,天天向上。
3楼2010-11-03 07:21:19
已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖

zyj8119

木虫 (著名写手)

引用回帖:
Originally posted by zyj8119 at 2010-11-03 07:21:19:

非常感谢!!!!

此贴结贴。
好好学习,天天向上。
4楼2010-11-03 07:25:52
已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖

magic7004

金虫 (职业作家)


小木虫(金币+0.5):给个红包,谢谢回帖交流
难道楼主用的是VC6吗?
流氓不可怕,可怕的是流氓有文化,有文化又BH的流氓无敌~~!
5楼2010-11-03 18:08:01
已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖

zyj8119

木虫 (著名写手)

引用回帖:
Originally posted by magic7004 at 2010-11-03 18:08:01:
难道楼主用的是VC6吗?

是的。。。
好好学习,天天向上。
6楼2010-11-09 20:13:11
已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖

magic7004

金虫 (职业作家)


小木虫(金币+0.5):给个红包,谢谢回帖交流
引用回帖:
Originally posted by zyj8119 at 2010-11-09 20:13:11:

是的。。。

VC6不支持C++标准的,玩纯C++的话一定要远离VC6,真爱生命。
流氓不可怕,可怕的是流氓有文化,有文化又BH的流氓无敌~~!
7楼2010-11-09 20:35:07
已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖

zyj8119

木虫 (著名写手)

引用回帖:
Originally posted by magic7004 at 2010-11-09 20:35:07:


VC6不支持C++标准的,玩纯C++的话一定要远离VC6,真爱生命。

那么dev-c++和mingw-studio呢?
好好学习,天天向上。
8楼2010-11-09 20:42:18
已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖
相关版块跳转 我要订阅楼主 zyj8119 的主题更新
最具人气热帖推荐 [查看全部] 作者 回/看 最后发表
[基金申请] 2024国社科通讯评审 +14 qsd10086 2024-06-13 29/1450 2024-06-18 15:23 by amberhubo
[高分子] 寻找聚酯反应釜 +3 茕茕恭煮 2024-06-15 6/300 2024-06-18 14:15 by 茕茕恭煮
[找工作] 初始合伙人来啦!(生物试剂耗材标准品) +13 欢快的小科研人 2024-06-15 24/1200 2024-06-18 13:08 by 欢快的小科研人
[硕博家园] 关于硕博连读的一些疑问? +5 Lwenter 2024-06-14 6/300 2024-06-18 12:49 by 博csc分享
[论文投稿] 投稿求助 10+3 2022_灵魂工程师 2024-06-16 8/400 2024-06-18 12:12 by 投必得科研顾问
[基金申请] 有人中过人文社科类的博后特助吗? +3 outsider1986 2024-06-16 5/250 2024-06-18 11:10 by 袁天未然
[考博] 34岁读博士晚吗 +32 emitdne 2024-06-13 32/1600 2024-06-18 08:44 by yuan0806
[基金申请] 博后基金刷到的BUG,图片来的更直观 +12 carolloo 2024-06-17 13/650 2024-06-18 08:35 by q478652742
[教师之家] 饶议:什么制度能保障大学普通教师不用为领导拎包,不用看领导脸色 +10 zju2000 2024-06-12 16/800 2024-06-17 14:54 by 大天尊
[基金申请] 希望今年自己国自然面上项目和老婆青年项目能中! +7 恐龙爸爸 2024-06-14 7/350 2024-06-16 14:48 by redfish105
[基金申请] 关于博后基金的bug问题 +6 lxr1991 2024-06-14 9/450 2024-06-15 21:17 by since—2010
[基金申请] 为什么我的博后基金还在流动站审核中?不会是学院给我卡了吧? +14 王凯12 2024-06-13 26/1300 2024-06-15 15:22 by 好人与坏人
[论文投稿] 求机械类四区sci推荐 5+3 迷茫小旷 2024-06-14 4/200 2024-06-15 11:25 by bobvan
[考研] 物理化学一对一辅导 +3 林大diao 2024-06-12 5/250 2024-06-14 20:57 by 林大diao
[有机交流] ππ堆积会发生在有机溶剂中吗 5+3 zibuyu0420 2024-06-13 4/200 2024-06-14 14:17 by 小肉干
[基金申请] 国自然基金公布的时候基金号有吗 +8 潇洒怡惜 2024-06-13 11/550 2024-06-14 11:24 by JRfei
[基金申请] 75批博后基金 +10 kyukitu 2024-06-13 13/650 2024-06-14 10:31 by kyukitu
[论文投稿] with editor日期变更 +3 慎独的小花卷 2024-06-12 8/400 2024-06-13 11:00 by 慎独的小花卷
[论文投稿] 摩擦磨损论文投稿 +3 jmysan 2024-06-12 3/150 2024-06-13 08:36 by 莱茵润色
[硕博家园] 申博 +3 悦悦小小鱼 2024-06-12 3/150 2024-06-12 15:11 by chen5805
信息提示
请填处理意见