I know C++ has converter. But to know how memory is working i should know why i can not do that:
#include <iostream>#include <cstring>int main() { const char* text = "hello"; std::wstring* wtext = malloc(5); strcpy(wtext, text); std::wcout << wtext << std::endl; free(wtext); return 0;}
"text" is pointer of "hello"
"wtext" is pointer of memory which contains free 5 bytes
function "strcpy" copies memory from pointer "text" to pointer "wtext"
"std::wcout" is printing out this all
"free" cleans old memory of pointer "wtext" \
If all of this theory is right ,then it should be working, but it is not.
Why can not i resize something and put it into this one?
so C++ compiler says i can not use "malloc" on "wtext" because it has not the same types of variable. However, professor says pointers can have any things in it, because it is pointers. They can point at numbers, text, e.t.c. I did not understand what had happened.