VC++ 6.0下:C++程序出错,求高人指点“哪里出错”了。。。谢谢!
代码如下:#include<iostream.h>classStudent{public:Student(){}Student(intn,char[]na,chars){...
代码如下:
#include <iostream.h>
class Student
{
public:
Student() {}
Student(int n,char[] na,char s) {num=n;name=na;sex=s;}
Student in()
{ num=1001;
name="lee";
sex='M'; }
Student out()
{ cout<<num<<" "<<name<<" "<<sex<<endl; }
private:
int num;
char[] name;
char sex;
};
int main()
{ Student s;
s.in();
s.out();
return 0;
}
错误提示如下:
--------------------Configuration: 4-7 - Win32 Debug--------------------
Compiling...
4-7.cpp
E:\C++\4-7.cpp(6) : error C2629: unexpected 'class Student ('
E:\C++\4-7.cpp(6) : error C2334: unexpected token(s) preceding '{'; skipping apparent function body
E:\C++\4-7.cpp(15) : error C2059: syntax error : '['
E:\C++\4-7.cpp(15) : error C2238: unexpected token(s) preceding ';'
执行 cl.exe 时出错.
4-7.obj - 1 error(s), 0 warning(s) 展开
#include <iostream.h>
class Student
{
public:
Student() {}
Student(int n,char[] na,char s) {num=n;name=na;sex=s;}
Student in()
{ num=1001;
name="lee";
sex='M'; }
Student out()
{ cout<<num<<" "<<name<<" "<<sex<<endl; }
private:
int num;
char[] name;
char sex;
};
int main()
{ Student s;
s.in();
s.out();
return 0;
}
错误提示如下:
--------------------Configuration: 4-7 - Win32 Debug--------------------
Compiling...
4-7.cpp
E:\C++\4-7.cpp(6) : error C2629: unexpected 'class Student ('
E:\C++\4-7.cpp(6) : error C2334: unexpected token(s) preceding '{'; skipping apparent function body
E:\C++\4-7.cpp(15) : error C2059: syntax error : '['
E:\C++\4-7.cpp(15) : error C2238: unexpected token(s) preceding ';'
执行 cl.exe 时出错.
4-7.obj - 1 error(s), 0 warning(s) 展开
2个回答
2012-04-22
展开全部
改一下就行了
Student(int n,char* na,char s)
char* name;//你那字符数组定义的时候出了问题
void in()//没返回值,定义void类型的函数
void out()
Student(int n,char* na,char s)
char* name;//你那字符数组定义的时候出了问题
void in()//没返回值,定义void类型的函数
void out()
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
#include <iostream>
using namespace std;
class Student
{
public:
Student() {}
Student(int n,char na[100],char s)
{
num=n;
strcpy(name,na);
sex=s;
}
void in()
{ num=1001;
strcpy(name,"lee");
//name="lee";
sex='M'; }
void out()
{ cout<<num<<" "<<name<<" "<<sex<<endl; }
private:
int num;
char name[100];
char sex;
};
int main()
{ Student s;
s.in();
s.out();
return 0;
}
using namespace std;
class Student
{
public:
Student() {}
Student(int n,char na[100],char s)
{
num=n;
strcpy(name,na);
sex=s;
}
void in()
{ num=1001;
strcpy(name,"lee");
//name="lee";
sex='M'; }
void out()
{ cout<<num<<" "<<name<<" "<<sex<<endl; }
private:
int num;
char name[100];
char sex;
};
int main()
{ Student s;
s.in();
s.out();
return 0;
}
追问
谢啦!!
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询