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 | - | 복사할 null 종료 바이트 문자열에 대한 포인터 |
반환값
dest
예제
이 코드 실행
#include <cstring> #include <iostream> #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 null terminator std::strcpy(dst.get(), src); dst[0] = 'M'; std::cout << src << '\n' << dst.get() << '\n'; }
출력:
Take the test. Make the test.
참고 항목
|
한 문자열에서 다른 문자열로 지정된 개수의 문자를 복사합니다
(함수) |
|
|
한 버퍼에서 다른 버퍼로 데이터를 복사합니다
(함수) |
|
|
C 문서
for
strcpy
|
|