Go back to Richel Bilderbeek's homepage.

Go back to Richel Bilderbeek's C++ page.

 

 

 

 

 

(C++) std::memcpy

 

std::memcpy (an abbreviation of 'memory copy') is an STL function to copy raw memory.

 

 

#include <cassert>
#include <cstring>
#include <string>
int main()
{
  //Create a scrambled std::string
  std::string s = "HellABCorld";

  //Create the std::string to fix s
  const std::string t = "o w";

  //Copy all three characters of t to the fifth character of s
  std::memcpy(&s[4],&t[0],3);

  //Assume std::memcpy worked
  assert(s == "Hello world");
}

 

 

 

 

 

Go back to Richel Bilderbeek's C++ page.

Go back to Richel Bilderbeek's homepage.

 

Valid XHTML 1.0 Strict

This page has been created by the tool CodeToHtml