Skip site navigation (1)Skip section navigation (2)

FreeBSD Manual Pages

  
 
  

home | help
std::strcpy(3)		      C++ Standard Libary		std::strcpy(3)

NAME
       std::strcpy - std::strcpy

Synopsis
	  Defined in header <cstring>
	  char*	strcpy(	char* dest, const char*	src );

	  Copies  the  character  string pointed to by src, including the null
       terminator, to the
	  character array whose	first element is pointed to by dest.

	  The behavior is undefined if the dest	array is not large enough. The
       behavior	is
	  undefined if the strings overlap.

Parameters
	  dest - pointer to the	character array	to write to
	  src  - pointer to the	null-terminated	byte string to copy from

Return value
	  dest

Example
       // Run this code

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

Output:
	Take the test.
	Make the test.

See also
	  strncpy copies a certain amount of characters	from one string	to an-
       other
		  (function)
	  memcpy  copies one buffer to another
		  (function)

http://cppreference.com		  2022.07.31			std::strcpy(3)

Want to link to this manual page? Use this URL:
<https://man.freebsd.org/cgi/man.cgi?query=std::strcpy&sektion=3&manpath=FreeBSD+Ports+15.0>

home | help