c++2005中string的问题!问什么老错?代码如下
来源:百度知道 编辑:UC知道 时间:2024/05/13 06:35:35
// 4.7.cpp : 定义控制台应用程序的入口点。
//
#include "stdafx.h"
#include "iostream"//只有调用这个库时不用加“.h”
#include <cstring>
#include <stdio.h>
using namespace std;//此处分号不能忘记
class Student
{
public:
Student(const char* Name,int Age,char* Sex,char* IdNo,char* Dept,float OS,float DS);
char* GetName()
{
return(name);
}
int GetAge();
char* GetSex();
char* GetIdNo();
char* GetDept();
float Aver();
void Display();
protected:
char name[20];
char sex[3];
int age;
char id[18];
char dept[30];
float os,ds;
};
Student::Student(const char* Name, int Age, char* Sex, char* IdNo, char* Dept, float OS, float DS)
{
char* strcpy(name,Name);//字符串拷贝
age=Age;
char* strcpy(sex,Sex);
char* strcpy(id,IdNo);
char* strcpy(dept,Dept);
os=OS;
ds=DS;
}
int Stude
//
#include "stdafx.h"
#include "iostream"//只有调用这个库时不用加“.h”
#include <cstring>
#include <stdio.h>
using namespace std;//此处分号不能忘记
class Student
{
public:
Student(const char* Name,int Age,char* Sex,char* IdNo,char* Dept,float OS,float DS);
char* GetName()
{
return(name);
}
int GetAge();
char* GetSex();
char* GetIdNo();
char* GetDept();
float Aver();
void Display();
protected:
char name[20];
char sex[3];
int age;
char id[18];
char dept[30];
float os,ds;
};
Student::Student(const char* Name, int Age, char* Sex, char* IdNo, char* Dept, float OS, float DS)
{
char* strcpy(name,Name);//字符串拷贝
age=Age;
char* strcpy(sex,Sex);
char* strcpy(id,IdNo);
char* strcpy(dept,Dept);
os=OS;
ds=DS;
}
int Stude
我来了,在vs2008下测试的,.就像二楼的那样更改就可以了!
去掉 Student初始化函数中的char* 就可以了
下面是我的执行代码:
// vs2005string.cpp : 定义控制台应用程序的入口点。
//
#include "stdafx.h"
#include "stdafx.h"
#include "iostream"//只有调用这个库时不用加“.h”
#include <cstring>
#include <stdio.h>
using namespace std;//此处分号不能忘记
class Student
{
public:
Student(const char* Name,int Age,char* Sex,char* IdNo,char* Dept,float OS,float DS);
char* GetName()
{
return(name);
}
int GetAge();
char* GetSex();
char* GetIdNo();
char* GetDept();
float Aver();
void Display();
protected:
char name[20];
char sex[3];
int ag