mardi 15 mai 2018

I initialize char *str1 = nullptr and output to the screen... But when i want output to other variable i receive empty screen.. Why is it happening?

#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
}

Aucun commentaire:

Enregistrer un commentaire