#include "stdafx.h"
#include
#include
using namespace std;
int main()
{
char *str = "hi,guys!";//若将*str替换为str[]便成功,为什么呢?
strcpy_s(str,6,"aaaaa");
cout << str << endl;
system("PAUSE");
return 0;
}
#include "stdafx.h"
#include
#include
using namespace std;
int main()
{
char *str = "hi,guys!";//若将*str替换为str[]便成功,为什么呢?
strcpy_s(str,6,"aaaaa");
cout << str << endl;
system("PAUSE");
return 0;
}
char *str;这代表声明一个字符串指针,默认值为空, 即nulll。
需要先为它开辟内存空间才行;
修改如下:
char *str=new char[10];
str="hi,guys!".
而char str[]="hi,guys!";这是声明字符串的方法。