strcpy 的问题

[复制链接]
查看11 | 回复3 | 2010-8-17 17:52:40 | 显示全部楼层 |阅读模式
#ifndef LZS1_H_
#define LZS1_H_
#include
#include
//#define NUM5
//int NUM;
using namespace std;
class student
{
private:
int number;
char name;
float score;
public:
void setstudent(int snumber,char sname,float sscore)
{
number=snumber;
score=sscore;
strcpy(name,sname);
}
void show()
{
coutnumber>>name>>score;
s.setstudent(number,name,score);
}
}
void guanli::output()
{
int i;
cout
#include"LZS1.h"
void main()
{
guanli m;
m.input();
cout<<"排序前的输出结果"<<endl;
m.output();
m.sort();
cout<<"排序后的输出结果"<<endl;
m.output();
}
这个程序的strcpy 为什么会说不能将参数从char 转换为char *
请叫高手

回复

使用道具 举报

千问 | 2010-8-17 17:52:40 | 显示全部楼层
函数: char *strcpy(char *str1,const char *str2 )的作用是: 将str2的内容拷贝至str1你的代码中: void setstudent(int snumber,char sname,float sscore){number=snumber;score=sscore;strcpy(name,sname); //此处改为name=sname;}name 和sname都是char类型的变量, 不能 用 strcpy
回复

使用道具 举报

千问 | 2010-8-17 17:52:40 | 显示全部楼层
strcpy()函数的参数就是指针或是数组,不能是简简单单的字符变量!!
回复

使用道具 举报

千问 | 2010-8-17 17:52:40 | 显示全部楼层
char name;char sname;char 和 char *差好远的
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

主题

0

回帖

4882万

积分

论坛元老

Rank: 8Rank: 8

积分
48824836
热门排行