Before(using ASCII) i was using std::string as buffer like this:
std::string test = ""; int value = 6; test.append("some string"); test.append((char*)value, 4); test.append("some string"); with expected value in test:
"some srtring\x6\x0\x0\x0somestring"
Now i am tring to use Unicode and i wanna keep the same "code" but trubles happens:
std::wstring test = ""; int value = 6; test.append("some string"); test.append((wchar_t*)value, 4); (buffer overflow cause reading 8 bytes) test.append("some string"); How can i append bytes like in std::string? Doing:
std::wstring test = ""; int value = 6; test.append("some string"); test.append((wchar_t*)value, 2); test.append("some string"); Solve partially the problem cause after i can't append bools.
EDIT: i can even use wstringstream if a binary copy is applied.(normally not)
std::wstring.std::to_stringandstd::to_wstring? (and use+for concat)static_cast<char*>(value)won't compile. Generally, astatic_castis at least safe. By not compiling, at least you might be deterred from trying to cast like that.(char*)valuetakes the bytes and reinterprets them as characters. Are you sure that's what you really want? Of course not, but the cast doesn't tell you that, likereinterpret_castdoes.std::string, either :)