C++ Tutorial/string/string copy — различия между версиями

Материал из C\C++ эксперт
Перейти к: навигация, поиск
м (1 версия: Импорт контента...)
 
м (1 версия: Импорт контента...)
 
(нет различий)

Текущая версия на 10:30, 25 мая 2010

Copy char array from a string to a char pointer

#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;
}
ptr2 is STRINGS