读书人

内存储器复制的目标太小

发布时间: 2012-08-09 15:59:21 作者: rapoo

内存复制的目标太小
C版本

#include <stdio.h>
int main()
{char * a[6];
a[6]="cazzo";
printf(a[6]);
return 0;}

C++版本
#include <iostream>//使用标准输入输出库
#include <string>
int main()
{using namespace std;
char * a[6];
a[6]="cazzo";
cout<<a[6];
return 0;}

编译前警告:内存复制的目标太小
错误提示:Stack around the variable 'a' was corrupted.

应该怎么修改?

[解决办法]
你改成这样:
#include <iostream>
#include <string>
int main()
{using namespace std;
char * a[6];//声明要了6个字符地址,下标分别是0到5
*a="cazzo";//直接把const char *的"cazzo"写到第一个地址里面去,后面依次排
cout<<*a;
return 0;}

读书人网 >C语言

热点推荐