So the issue is that when using c# the char is 4 bytes so "abc" is (65 0 66 0 67 0).
When inputing that to a wstring in c++ thru sending it in a socket i get the following output a.
How i am able to convert such a string to a c++ string?
Sounds like you need ASCII or UTF-8 encoding instead of Unicode.
65 0 66 0 67 0 is only going to get you the A, since the next zero is interpreted as a null termination character in C++.
Strategies for converting Unicode to ASCII can be found here.
wstring however.u16string on C++'s side. The 7-bit US-ASCII encoding will mangle any non-English text. UTF8 will emit the same bytes as US-ASCII for English textusing c# the char is 4 bytes
No, in CSharp Strings are encoded in UTF16. Code units need at least two bytes in UTF16. For simple charachters a single code unit can represent a code point (e.g. 65 0).
On Windows wstring is usually UTF16 (2-4 Bytes) encoded, too. But on Unix/Linux wstring uses usually UTF32-Encoding (always 4 Bytes).
The Unicode code Point has the same numerical value compared to ASCII - therefore UTF-16 encoded ASCII text looks often like this: {num} 0 {num} 0 {num} 0... See the details here: (https://en.wikipedia.org/wiki/UTF-16)
Could you show us some Code, how you constructed your wstring object? The null byte is critical here, because it was the end marker for ASCII / ANSI Strings.
std::vector<char> data = socket.read(); then std::wcout << std::wstring(data.begin(), data.end()); sorry for syntax erorrs (if any) written in this box also i dont know how to print a u16string but i have tried it in my file pharser and it didnt change any thing
i get the following output a.that's because you tried the bytes as astd:string, which is suitable only for single-byte codepages or, due to lack of standardization in C++, UTF8. This interpreted the first null byte as the end of a string. You should usestd::u16stringto read UTF16 bytes.0x00byte for UTF8, or two0x00for UTF16.