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

标签 c++ c

我有一个 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/

相关文章:

c++ - 如何包装std::vector以在纯C中使用

c - 使用 if 语句评估连续回复

c++ - C++中运行时和编译时多态性之间的区别

c++ - Cocos2dxv3.0-pre-alpha0 应用商店上传(64 位不支持)问题

c++ - 将 Cimg 转换为 ITK

c++ - LPBYTE 宏在编译时生成错误 - C++

c - 将结构参数的名称作为参数发送

c - 堆栈粉碎保护和缓冲区溢出的问题

C、时钟函数仅返回0.00000

c++ - C++ 和 Fortran 中的不同精度