各位老师求助哇,呜呜呜,c++中memcpy问题求解!在最后会引发xmemory异常,什么原因啊 20

#include<iostream>#include<cstring>usingnamespacestd;intmain(){inta[55],n,num;stringc... #include<iostream>#include<cstring>using namespace std;int main() {int a[55], n, num; string c[55] = { "0" ,"S1","S2","S3","S4","S5","S6","S7","S8","S9","S10","S11","S12","S13","H1" ,"H2" ,"H3" ,"H4" ,"H5" ,"H6" ,"H7" ,"H8" ,"H9" ,"H10" ,"H11" ,"H12" ,"H13" ,"C1" ,"C2" ,"C3" ,"C4" ,"C5" ,"C6" ,"C7" ,"C8" ,"C9" ,"C10" ,"C11" ,"C12" ,"C13" ,"D1" ,"D2" ,"D3" ,"D4" ,"D5" ,"D6" ,"D7" ,"D8" ,"D9" ,"D10" ,"D11" ,"D12" ,"D13" ,"J1" ,"J2" };string b[55];cin >> n;for (int i = 1; i < 55; i++){cin >> num;a[i] = num;}for (int i = 0; i < n; i++){for (int j = 1; j < 55; j++){b[a[j]] = c[j];}//memset(c, 0, sizeof(c));memcpy(c,b,sizeof(c)); }for (int i = 1; i < 54; i++){cout << b[i] << " ";}cout << b[54];return 0;}输入为这个 展开
 我来答
80老人
2019-08-12 · TA获得超过3272个赞
知道大有可为答主
回答量:3857
采纳率:66%
帮助的人:138万
展开全部
当然了,你的b中是54个数,你非要把55个数赋值进去就内存溢出了。
问题在你的循环赋值定义i=1上,应该是i=0;i<54这样才会把55个数值赋进去。
追问
哇老师您好,不太明白鸭,我的是b[55],虽然b里面确定赋值的是b[1]~b[54],的确是54个,
b[0]并没有赋值,后面我是从b[1]开始输出的,b[0]里面应该是个随机的机器数.memcpy(c,b,sizeof(c))不是把b赋值到c中么,赋值长度为sizeof(c),c和b都开了55个空间啊,sizeof(c)==sizeof(b);他们大小一样,为什么会在复制的时候会内存溢出鸭
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式