Deprecated: Constant E_STRICT is deprecated in /var/www/cppe.ru/www/includes/exception/MWExceptionHandler.php on line 179
Deprecated: Creation of dynamic property PPDStack::$accum is deprecated in /var/www/cppe.ru/www/includes/parser/Preprocessor_DOM.php on line 803
Deprecated: Constant E_STRICT is deprecated in /var/www/cppe.ru/www/includes/exception/MWExceptionHandler.php on line 179
Deprecated: Constant E_STRICT is deprecated in /var/www/cppe.ru/www/vendor/mediawiki/at-ease/src/Functions.php on line 48
Материал из C\C++ эксперт
(разн.) ← Предыдущая | Текущая версия (разн.) | Следующая → (разн.)
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