以文本方式查看主题

-  中文XML论坛 - 专业的XML技术讨论区  (http://bbs.xml.org.cn/index.asp)
--  『 C/C++编程思想 』  (http://bbs.xml.org.cn/list.asp?boardid=61)
----  大虾[求助]  (http://bbs.xml.org.cn/dispbbs.asp?boardid=61&rootid=&id=61064)


--  作者:伟伟联盟
--  发布时间:4/8/2008 8:41:00 PM

--  大虾[求助]
[B][size=4][这是我的考试题目,当我调试运行时总是显示某处错误,最后面是错误说明,请大侠指点。

#include <iostream.h>
#include <string.h>
class CStudent
{
private:
 char name[30];
 int code;
 double score;
public:
 CStudent(char* nm)
{
    strcpy(name,nm);       
}
 CStudent(){}
 void putname(char* nm){ strcpy(name, nm);}
 void putcode(int d){ code=d;}
 void putscore(double sc){ score=sc;}
 void getname(char* nm){ strcpy(nm, name);}
 double getcode(){ return code;}
 double getscore(){ return score;}
 void addscore(double sc)
{
    score+=sc;
}
};
class CGraduateStudent: public CStudent
{
private:
 char advisor[30];
 int paper;
public:
 void putadvisor(char* nm){ strcpy(advisor, nm);}
 void getadvisor(char* nm){ strcpy(nm, advisor);}
 void putpaper(int d){ paper=d;}
 void addpaper (int d){paper+=d;}
 int getpaper(){ return paper;}
};
void main()
{
 CGraduateStudent sdt;
 sdt.putname("Hanson");
 sdt.putadvisor("MichaelPhong");
 sdt.putpaper(8);
    std.addpaper(2);
 char csname[30];
 sdt.getname(csname);
 char caname[30];
 sdt.getadvisor(caname);
 cout<<"Student "<<csname<<endl;
 cout<<"(Advisor: "<<caname<<")"<<endl;
 cout << "Total paper is " << sdt.getpaper() <<endl;
}

运行后提示:
正在编译...
stdafx.cpp
正在编译...
7.cpp
c:\documents and settings\administrator\my documents\visual studio 2005\projects\7\7\7.cpp(23) : warning C4996: “strcpy”被声明为否决的
        e:\c++\vc\include\string.h(73) : 参见“strcpy”的声明
        消息:“This function or variable may be unsafe. Consider using strcpy_s instead. To disable deprecation, use _CRT_SECURE_NO_DEPRECATE. See online help for details.”
c:\documents and settings\administrator\my documents\visual studio 2005\projects\7\7\7.cpp(26) : warning C4996: “strcpy”被声明为否决的
        e:\c++\vc\include\string.h(73) : 参见“strcpy”的声明
        消息:“This function or variable may be unsafe. Consider using strcpy_s instead. To disable deprecation, use _CRT_SECURE_NO_DEPRECATE. See online help for details.”
c:\documents and settings\administrator\my documents\visual studio 2005\projects\7\7\7.cpp(29) : warning C4996: “strcpy”被声明为否决的
        e:\c++\vc\include\string.h(73) : 参见“strcpy”的声明
        消息:“This function or variable may be unsafe. Consider using strcpy_s instead. To disable deprecation, use _CRT_SECURE_NO_DEPRECATE. See online help for details.”
c:\documents and settings\administrator\my documents\visual studio 2005\projects\7\7\7.cpp(43) : warning C4996: “strcpy”被声明为否决的
        e:\c++\vc\include\string.h(73) : 参见“strcpy”的声明
        消息:“This function or variable may be unsafe. Consider using strcpy_s instead. To disable deprecation, use _CRT_SECURE_NO_DEPRECATE. See online help for details.”
c:\documents and settings\administrator\my documents\visual studio 2005\projects\7\7\7.cpp(44) : warning C4996: “strcpy”被声明为否决的
        e:\c++\vc\include\string.h(73) : 参见“strcpy”的声明
        消息:“This function or variable may be unsafe. Consider using strcpy_s instead. To disable deprecation, use _CRT_SECURE_NO_DEPRECATE. See online help for details.”
c:\documents and settings\administrator\my documents\visual studio 2005\projects\7\7\7.cpp(55) : error C2882: “std”: 在表达式中非法使用命名空间标识符
c:\documents and settings\administrator\my documents\visual studio 2005\projects\7\7\7.cpp(55) : error C2228: “.addpaper”的左边必须有类/结构/联合
生成日志保存在“file://c:\Documents and Settings\Administrator\My Documents\Visual Studio 2005\Projects\7\7\Debug\BuildLog.htm”
7 - 2 个错误,5 个警告
========== 生成: 0 已成功, 1 已失败, 0 最新, 0 已跳过 ==========[/size][/size][/size][/size][/size][/size][/size][/B]


--  作者:卷积内核
--  发布时间:4/9/2008 4:01:00 PM

--  
你最好在VC6下编译,因为很多函数在visual studio 2005中支持的不是很好,有很多warning是正常的。


--  作者:卷积内核
--  发布时间:4/9/2008 4:05:00 PM

--  
void main()
{
CGraduateStudent sdt;
sdt.putname("Hanson");
sdt.putadvisor("MichaelPhong");
sdt.putpaper(8);
std.addpaper(2); //-----拼写错误 std -》sdt
char csname[30];
sdt.getname(csname);
char caname[30];
sdt.getadvisor(caname);
cout<<"Student "<<csname<<endl;
cout<<"(Advisor: "<<caname<<")"<<endl;
cout << "Total paper is " << sdt.getpaper() <<endl;
}


这样应该可以编译过去了。


W 3 C h i n a ( since 2003 ) 旗 下 站 点
苏ICP备05006046号《全国人大常委会关于维护互联网安全的决定》《计算机信息网络国际联网安全保护管理办法》
46.875ms