向VC++高手求救

来源:百度知道 编辑:UC知道 时间:2024/05/11 02:55:46
请VC++高手帮忙改正里面的错误,错误为:
1、dsfdf.cpp(105) : error C2440: '=' : cannot convert from 'char [8]' to 'char [10]'
There is no context in which this conversion is possible
2、dsfdf.cpp(106) : error C2440: '=' : cannot convert from 'char [4]' to 'char [6]'
There is no context in which this conversion is possible
3、dsfdf.cpp(107) : error C2440: '=' : cannot convert from 'char [7]' to 'char [6]'
There is no context in which this conversion is possible
Error executing cl.exe.

明天就交作业了,急啊!!谢谢!

源代码为:

#include <iostream.h>
#include <process.h>
#include <string.h>
#include <conio.h>
#include <stdio.h>
#include <iomanip.h>
#define MAX 50
#define NULL 0

typedef struct Customer //已定票乘客信息
{
char Name[10]; //姓名
int Amount; //定票数
int Rank;

LZ在给结构体里的char数组成员赋值时是不是直接用等号赋值?
比如给Flight中的Des_Name:
XXX.Des_Name="sssssss";

应该用strcpy()拷贝进去。

[补充] 以你的代码为例
用strcpy(): strcpy(u->Des_Name, "Guazhou");
用strncpy()更安全: strncpy(u->Des_Name, "Guazhou", 10-1);
但最好在使用u之前,利用memset把结构体清零。

字符串的长度不一致,你用字符串复制函数