std:: strcpy
From cppreference.net
C++
Text processing library
| Localization library | |||||||||||||||||||||||||
| Regular expressions library (C++11) | |||||||||||||||||||||||||
| Formatting library (C++20) | |||||||||||||||||||||||||
| Null-terminated sequence utilities | |||||||||||||||||||||||||
| Byte strings | |||||||||||||||||||||||||
| Multibyte strings | |||||||||||||||||||||||||
| Wide strings | |||||||||||||||||||||||||
| Primitive numeric conversions | |||||||||||||||||||||||||
|
|||||||||||||||||||||||||
| Text encoding identifications | |||||||||||||||||||||||||
|
|||||||||||||||||||||||||
Null-terminated byte strings
| Functions | ||||||||||||||||||||||||||||||||||||
| Character classification | ||||||||||||||||||||||||||||||||||||
| Character manipulation | ||||||||||||||||||||||||||||||||||||
| Conversions to numeric formats | ||||||||||||||||||||||||||||||||||||
|
|
|||||||||||||||||||||||||||||||||||
| String manipulation | ||||||||||||||||||||||||||||||||||||
| String examination | ||||||||||||||||||||||||||||||||||||
| Character array functions | ||||||||||||||||||||||||||||||||||||
| Miscellaneous | ||||||||||||||||||||||||||||||||||||
|
定义于头文件
<cstring>
|
||
|
char
*
strcpy
(
char
*
dest,
const
char
*
src
)
;
|
||
将指向 src 的字符串(包括空终止符)复制到由 dest 指向首元素的字符数组中。
如果 dest 数组不够大,则行为未定义。如果字符串重叠,则行为未定义。
目录 |
参数
| dest | - | 指向要写入的字符数组的指针 |
| src | - | 指向要复制的以空字符结尾的字节字符串的指针 |
返回值
dest
示例
运行此代码
#include <cstring> #include <iostream> #include <memory> int main() { const char* src = "Take the test."; // src[0] = 'M'; // 无法修改字符串字面值 auto dst = std::make_unique<char[]>(std::strlen(src) + 1); // +1 用于空终止符 std::strcpy(dst.get(), src); dst[0] = 'M'; std::cout << src << '\n' << dst.get() << '\n'; }
输出:
Take the test. Make the test.
参见
|
将指定数量的字符从一个字符串复制到另一个字符串
(函数) |
|
|
将一个缓冲区复制到另一个缓冲区
(函数) |
|
|
C 文档
关于
strcpy
|
|