gpt4 book ai didi

c++ - 将嵌套结构变量从 C++ 传递到 C++ dll 会导致 (L"Buffer is too small"&& 0)

转载 作者:行者123 更新时间:2023-11-28 00:55:20 25 4
gpt4 key购买 nike

我有结构

NewStruct1
{
uint factor;
NewStruct2 assert[3];
char name[21];

}

还有一个

NewStruct2 
{
uint newFactor;
char newName[21];
}

这里我在dll中调用了一个函数'func',如下所示

NewStruct1 var;

func(&var);

函数是

func(NewStruct1 *v)
{
std::string myName = "werttt";
strcpy_s(v->assert[0].newName, myName.size(), myName.c_str());
}

这样做时 strcpy_s 给出 (L"Buffer is too small"&& 0) 即使有足够的空间容纳。任何人都可以帮我解决这个问题吗?

最佳答案

strcpy_s 的第二个参数必须是 destination 中的元素数,即 21(newName 中的字符数),不是源的长度。

关于c++ - 将嵌套结构变量从 C++ 传递到 C++ dll 会导致 (L"Buffer is too small"&& 0),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11753939/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com