gpt4 book ai didi

C++ `assign()` 等价于 C

转载 作者:行者123 更新时间:2023-11-30 21:49:09 30 4
gpt4 key购买 nike

关于如何在 C 中实现 C++ 的任何想法 assign()

C++ 代码示例:

std::string ds;
// snip //
ds.assign((const char *)start, end - start);

在 C 中使用相同的语法,编译时出现以下错误:

error: request for member 'assign' in something not a structure or union

最佳答案

您想在 C 中使用 C 字符串,请在 string.h 中查找与 C 字符串一起使用的函数(例如 strcpy)

http://www.cplusplus.com/reference/cstring/strcpy/

关于C++ `assign()` 等价于 C,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22335787/

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