我是C++的初学者,遇到一个问题很迷惑!希望高手指点一下,先谢谢了!
程序如下:
#include<iostream.h>
#include<string.h>
class employee
{
public:
employee(char * name,char * street,char * city,char * province,char * zip)
{
strncpy(names,name,sizeof(name));
name[sizeof(name)-1]='\0';
strncpy(streets,street,sizeof(street));
streets[sizeof(street)-1]='\0';
strncpy(citys,city,sizeof(city));
citys[sizeof(city)-1]='\0';
strncpy(provinces,province,sizeof(province));
province[sizeof(province)-1]='\0';
strncpy(zips,zip,sizeof(zip));
zips[sizeof(zip)-1]='\0';
}
void changename(char * name)
{
strncpy(names,name,sizeof(name));
name[sizeof(name)-1]='\0';
}
void display()
{
cout<<"name="<<names<<"/"<<"street="<<streets
<<"/"<<"city="<<citys<<"/"<<"province="<<provinces
<<"/"<<"zip="<<"/"<<zips<<endl;
}
protected:
char names[50];
char streets[50];
char citys[50];
char provinces[50];
char zips[50];
};
void main()
{
employee a("蓝","中关村","北京","北京","1010001");
a.display();
a.changename("风");
a.display();
}
程序在运行中报错:“ox004701122”指令引用的"0x0042601f"内存。该内存不能为"written"。
这是怎么回事呀!
[求助]