在线文档教程
C++
字符串 | Strings

std::strcpy

STD::strcpy

Defined in header
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...

二次

#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'; }

二次

产出:

二次

Take the test. Make the test.

二次

另见

strncpycopies a certain amount of characters from one string to another (function)
memcpycopies one buffer to another (function)

c strcpy文档

© cppreference.com

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

http://en.cppreference.com/w/cpp/string/字节/strcpy