Я инициализирую char * str1 = nullptr и выводю на экран ... Но когда я хочу выводить в другую переменную, я получаю пустой экран .. Почему это происходит? - PullRequest
0 голосов
/ 15 мая 2018
#include <iostream>
#include <cstring>

int main()
{
const char *str = "Hello world";
char *str1 = nullptr;

std::cout << str << std::endl;  // when i output to screan i see hello world
std::cout << str1 << std::endl; // when i output to scream i sen nothing

str1 = new char[strlen(str) + 1];
strcpy(str1, str);
std::cout << str <<  std::endl; // when i output to scream again i sen nothing
std::cout << str1 << std::endl; // The same
}
...