User Tools

Site Tools


c_-_c_strings:copy_a_string

C - C++ Strings - Copy a string

#include <iostream>
using std::cout;
using std::endl;
 
#include <string>
using std::string;
 
int main()
{
  string string1( "STRINGS" );
 
  int length = string1.length();
  char *ptr2 = new char[ length + 1 ];
 
  string1.copy( ptr2, length, 0 );
  ptr2[ length ] = '\0';
 
  cout << "\nptr2 is " << ptr2 << endl;
  delete [] ptr2;
 
  return 0;
}
c_-_c_strings/copy_a_string.txt · Last modified: 2020/07/15 09:30 by 127.0.0.1

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki