主题:一个关于二维字符数组的问题(恳求大侠帮忙)
//---------------------------------------------------------------------------
//问题如以下注解,直接COPY到BCB中就可运行
#pragma hdrstop
#include <iostream.h>
#include <conio.h>
//#include <vcl.h>
#include <stdio.h>
#include <string.h>
//---------------------------------------------------------------------------
#pragma argsused
class Employes
{
public:
Employes(char *[],int n);
void ChangeName(char nn[]);
void Display();
protected:
char Mdezhe[4][16];
};
int main(int argc, char* argv[])
{
char *gggg[]={"李辉","交通局宿舍","南宁市","广西自治区","530100"};
int m=sizeof(gggg)/sizeof(char*);
Employes demo(gggg,m);
demo.Display();
char mmm[]="lihui202";//不知为何这句竞修改了Mdezhe[4][16]的值
//demo.Display();
demo.ChangeName(mmm);
getche();
return 0;
}
Employes::Employes(char * dezhe[],int n)
{
int j=0;
while(j<n)
{
strcpy(Mdezhe[j],dezhe[j]);
j++;
}
cout<<"Constructing with a Mdezhe.\n ";
cout<<Mdezhe[4];
}
void Employes::ChangeName(char nn[])
{
// cout<<Mdezhe[4]<<"\n";
strcpy(Mdezhe[0],nn);
cout<<"ChangeName is running!\n"<<Mdezhe[0]<<"\n" ;
cout<<Mdezhe[4];//我的程序只改变了Mdezhe[0],为什么连Mdezhe[4]的值也变了
//Mdezhe[0]和Mdezhe[4]里的值竞一样,我晕、、、、、
}
void Employes::Display()
{
int i=5;
for(int j=0;j<i;j++)
{
cout<<"Mdezhe["<<j<<"][16] is\n "<<Mdezhe[j]<<endl;
}
cout<<"\n";
}
//问题如以下注解,直接COPY到BCB中就可运行
#pragma hdrstop
#include <iostream.h>
#include <conio.h>
//#include <vcl.h>
#include <stdio.h>
#include <string.h>
//---------------------------------------------------------------------------
#pragma argsused
class Employes
{
public:
Employes(char *[],int n);
void ChangeName(char nn[]);
void Display();
protected:
char Mdezhe[4][16];
};
int main(int argc, char* argv[])
{
char *gggg[]={"李辉","交通局宿舍","南宁市","广西自治区","530100"};
int m=sizeof(gggg)/sizeof(char*);
Employes demo(gggg,m);
demo.Display();
char mmm[]="lihui202";//不知为何这句竞修改了Mdezhe[4][16]的值
//demo.Display();
demo.ChangeName(mmm);
getche();
return 0;
}
Employes::Employes(char * dezhe[],int n)
{
int j=0;
while(j<n)
{
strcpy(Mdezhe[j],dezhe[j]);
j++;
}
cout<<"Constructing with a Mdezhe.\n ";
cout<<Mdezhe[4];
}
void Employes::ChangeName(char nn[])
{
// cout<<Mdezhe[4]<<"\n";
strcpy(Mdezhe[0],nn);
cout<<"ChangeName is running!\n"<<Mdezhe[0]<<"\n" ;
cout<<Mdezhe[4];//我的程序只改变了Mdezhe[0],为什么连Mdezhe[4]的值也变了
//Mdezhe[0]和Mdezhe[4]里的值竞一样,我晕、、、、、
}
void Employes::Display()
{
int i=5;
for(int j=0;j<i;j++)
{
cout<<"Mdezhe["<<j<<"][16] is\n "<<Mdezhe[j]<<endl;
}
cout<<"\n";
}