1. Используйте итераторы и включите нулевой терминатор
Код: Выделить всё
{
std::string test{"hello, world!"};
char* output = new char[test.size() + 1];
std::copy(test.begin(), test.end(),
output);
output[test.size() + 1] = '\0';
std::cout
Подробнее здесь: [url]https://stackoverflow.com/questions/37362473/modern-c-way-to-copy-string-into-char[/url]
Мобильная версия