首页
学习
活动
专区
工具
TVP
发布
精选内容/技术社群/优惠产品,尽在小程序
立即前往

std::strcpy

Defined in header <cstring>

char* strcpy( char* dest, const char* src );

复制所指向的字符串。src,包括空终止符,指向其第一个元素的字符数组。dest...

如果dest数组不够大。如果字符串重叠,则行为未定义。

参数

dest

-

pointer to the character array to write to

src

-

pointer to the null-terminated byte string to copy from

返回值

dest...

二次

代码语言:javascript
复制
#include <iostream>
#include <cstring>
#include <memory>
 
int main()
{
    const char* src = "Take the test.";
//  src[0] = 'M'; // can't modify string literal
    auto dst = std::make_unique<char[]>(std::strlen(src)+1); // +1 for the null terminator
    std::strcpy(dst.get(), src);
    dst[0] = 'M';
    std::cout << src << '\n' << dst.get() << '\n';
}

二次

产出:

二次

代码语言:javascript
复制
Take the test.
Make the test.

二次

另见

strncpy

copies a certain amount of characters from one string to another (function)

memcpy

copies one buffer to another (function)

c strcpy文档

代码语言:txt
复制
 © cppreference.com

在CreativeCommonsAttribution下授权-ShareAlike未移植许可v3.0。

扫码关注腾讯云开发者

领取腾讯云代金券