64,642
社区成员
发帖
与我相关
我的任务
分享
#include<iostream>
using namespace std;
class A
{
public:
A():a("hello"){}
private:
char a[20];
};
#include<iostream>
using namespace std;
class A
{
public:
A()
{strcpy(a,"hello");}
private:
char a[20];
};
cat main.cpp
#include <cstdio>
#include <iostream>
#include <cstdlib>
using namespace std;
class A
{
public:
A():a({0x30, 0x32, 0x33}){}
//private:
public:
char a[20];
};
int main()
{
A t;
cout << t.a[1] << endl;
return 0;
}
A(){strcpy(a,"Hello");}
char*a="hello";//这是把指针a指向一个存有“hello”的常量内存区
char a[20];
a = "hello";//错在a是个常量指针,不能改变它所指向的区域
具体参考这个http://topic.csdn.net/u/20120328/17/286602b3-a08e-4c8d-96e8-981fd858fa7f.html我的回答string str;
char a*=str.c_str();