Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR CPP

c++ copy string

#include <iostream>
#include <string.h>

/*
std::copy(void *, void *, void *)
1st arg: source begin
2nd arg: source end
3rd arg: destination address
*/

int main() 
{
	char *mystring{new char[20]{}};
	
	strcat(mystring, "Its Grepper");
	
    char *deststring{new char[20]{}};
    
    strcat(deststring, "Hello ");
    
    std::copy(mystring + 4, mystring + 12, deststring + strlen(deststring));
    
    std::cout << deststring << std::endl;
    
    
    
    delete[] mystring;
    delete[] deststring;
  
  /*
  output : Hello Grepper
  */
}
Source by softhunt.net #
 
PREVIOUS NEXT
Tagged: #copy #string
ADD COMMENT
Topic
Name
8+3 =