gpt4 book ai didi

c++ - 等价于 C++ 中的 C strcpy

转载 作者:太空宇宙 更新时间:2023-11-03 10:30:08 25 4
gpt4 key购买 nike

我有一个 C 代码,

struct sFoo
{
char* name;
char* fullname;
};

sFoo* foo = (sFoo*)malloc(sizeof(sFoo));
foo->name = (char*)malloc(10);

strcpy(foo->name, "HELLO");

C++ 中的 strcpy 等价于什么?

最佳答案

你可以使用 std::string

int main()
{
std::string myString = "Hello, there!";

std::string myOtherString = myString; //Makes a copy of myString


}

std::string 是标准的 C++ 字符串类型,它可以为您处理复制!

关于c++ - 等价于 C++ 中的 C strcpy,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19129852/

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