为什么VC不行
#include <string.h>
class student
{
char name[33];
public:
student() {}
student (char *p)
{
strcpy(name,p);
name[sizeof(name)-1]='\0';
}
};
#include <iostream.h>
void()
{
student st[2]("zhang","lisi");
}
为什么VC不行
#include <string.h>
class student
{
char name[33];
public:
student() {}
student (char *p)
{
strcpy(name,p);
name[sizeof(name)-1]='\0';
}
};
#include <iostream.h>
void()
{
student st[2]("zhang","lisi");
}
#include <iostream.h>
#include <string.h>
class student
{
char name[33];
public:
student() {}
student (char *p)
{
strcpy(name,p);
name[sizeof(name)-1]='\0';
}
void display()
{
cout<<name<<endl;
}
};
void main()
{
student st[2]={"zhang","lisi"}; //你这个搞错了!!
st[0].display();
st[1].display();
}
为什么不能用()初始化
而是=
#include <iostream.h>
#include <string.h>
class student
{
char name[33];
public:
student() {} 为什么要有这一句亚
student (char *p)
{
strcpy(name,p);
name[sizeof(name)-1]='\0';
}
void display()
{
cout<<name<<endl;
}
};
void main()
{
student st[2]={"zhang","lisi"}; //你这个搞错了!!
st[0].display();
st[1].display();
}
#include <iostream.h>
#include <string.h>
class student
{
char name[33];
public:
student() {}
student (char *p)
{
strcpy(name,p);
name[sizeof(name)-1]='\0';
}
void display()
{
cout<<name<<endl;
}
};
void main()
{
student st[2]={"zhang","lisi"}; //你这个搞错了!!
st[0].display();
st[1].display();
}
对数组的赋值就应该是A[n]={"","",""...""};