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