📄 subject_29340.htm
字号:
<p>
序号:29340 发表者:11 发表日期:2003-02-04 21:49:09
<br>主题:请各位高手帮我看看
<br>内容:我编了个程序,用DEV-C++编译,程序如下:<BR>#include <iostream.h><BR>#include <stdlib.h><BR>class Student<BR>{<BR> int number;<BR> char name[];<BR> int age;<BR> public:<BR><BR> void setvalue(int x, char y[],int z)<BR> { number=x;<BR> int j=0;<BR> int count=0;<BR> while(y[j]!='\0')<BR> {<BR> count++;<BR> j++;<BR> )<BR> for (int i=0;i<=count;i++) name[i]=y[i];<BR> age=z;<BR> }<BR> void print()<BR> {<BR> cout<<"No:"<<number<<"; "<<"Name:"<<name;<BR> cout<<"; "<<"Age:"<<age<<endl;<BR> }<BR>但老提示有错,错误题示:<BR> parse error at end of input<BR><BR>请指教。<BR>
<br><a href="javascript:history.go(-1)">返回上页</a><br><a href=http://www.copathway.com/cndevforum/>访问论坛</a></p>
<hr size=1>
<blockquote><p>
回复者:tjhe 回复日期:2003-02-05 00:28:21
<br>内容:好像类定义没有结束:<BR><BR>class student<BR>{<BR><BR>.....<BR><BR>}; //此}与分号;不能少
<br>
<a href="javascript:history.go(-1)">返回上页</a><br><a href=http://www.copathway.com/cndevforum/>访问论坛</a></p></blockquote>
<hr size=1>
<blockquote><p>
回复者:mr_oydy 回复日期:2003-02-05 13:57:09
<br>内容:c99标准需然可以这样写:char name[];<BR>但应该是要加一个长度的.char name[255];
<br>
<a href="javascript:history.go(-1)">返回上页</a><br><a href=http://www.copathway.com/cndevforum/>访问论坛</a></p></blockquote>
<hr size=1>
<blockquote><p>
回复者:11 回复日期:2003-02-05 20:29:49
<br>内容:源程序中是有分号的
<br>
<a href="javascript:history.go(-1)">返回上页</a><br><a href=http://www.copathway.com/cndevforum/>访问论坛</a></p></blockquote>
<hr size=1>
<blockquote><p>
回复者:11 回复日期:2003-02-05 20:31:34
<br>内容:mr_oydy:我试了,<BR>不行。
<br>
<a href="javascript:history.go(-1)">返回上页</a><br><a href=http://www.copathway.com/cndevforum/>访问论坛</a></p></blockquote>
<hr size=1>
<blockquote><p>
回复者:~榴莲飘飘~ 回复日期:2003-02-05 21:43:33
<br>内容:类定义只有{ 没有 } <BR>是你输入错误还是你编的就是这?<BR><BR>还有定义类的成员函数最好不要在定义类的时候定义.<BR>还有没有main()函数吗?<BR>在写一段main()函数试一试~<BR>用main函数调用类的接口程序.
<br>
<a href="javascript:history.go(-1)">返回上页</a><br><a href=http://www.copathway.com/cndevforum/>访问论坛</a></p></blockquote>
<hr size=1>
<blockquote><p>
回复者:11 回复日期:2003-02-06 13:27:55
<br>内容:main()函数原程序中有的:<BR>void main()<BR>{<BR> Student stu1,stu2;<BR> stu1.setvalue(1,"牛新元",27);<BR> stu1.print();<BR> stu2.setvalue(2,"潘 昊",25);<BR> stu2.print();<BR>}
<br>
<a href="javascript:history.go(-1)">返回上页</a><br><a href=http://www.copathway.com/cndevforum/>访问论坛</a></p></blockquote>
<hr size=1>
<blockquote><p>
<font color=red>答案被接受</font><br>回复者:mr_oydy 回复日期:2003-02-06 14:27:19
<br>内容:#include <iostream.h><BR>#include <cstring><BR>#include <cassert><BR>#include <stdlib.h><BR>//#include "pause.h"<BR><BR>#define NAME_MAX 256<BR>class Student{<BR>public:<BR>void setvalue(int StuNum, char StuName[],int StuAge){ <BR> number=StuNum;<BR> int j=0;<BR> int count=0;<BR> <BR> assert(strlen(StuName)<NAME_MAX-1);<BR> <BR> while(StuName[j]!='\0'){<BR> count++;<BR> j++;<BR> }<BR> <BR> for (int i=0; i<=count; i++)<BR> name[i] = StuName[i]; // end of for<BR> <BR> age = StuAge;<BR>}<BR> <BR>void print(){<BR> cout << "No:" << number << "; "<BR> << "Name:" << name <<"; " <BR> << "Age:" << age << endl;<BR>}<BR><BR>private:<BR> int number;<BR> char name[NAME_MAX];<BR> int age;<BR><BR>};<BR> <BR>void main(){<BR> Student stu1,stu2;<BR> stu1.setvalue(1,"牛新元",27);<BR> stu1.print();<BR> stu2.setvalue(2,"潘 昊",25);<BR> stu2.print();<BR>}
<br>
<a href="javascript:history.go(-1)">返回上页</a><br><a href=http://www.copathway.com/cndevforum/>访问论坛</a></p></blockquote>
<hr size=1>
<blockquote><p>
回复者:11 回复日期:2003-02-07 14:58:46
<br>内容:我找到我的问题了,<BR>有一各}我写成)了<BR>谢谢各位
<br>
<a href="javascript:history.go(-1)">返回上页</a><br><a href=http://www.copathway.com/cndevforum/>访问论坛</a></p></blockquote>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -