Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why use MultiByteToWideCharArray to convert std::string to std::wstring?

Tags:

c++

I want to convert a std::string to std::wstring. There are two approaches which i have come across.

  1. Given a string str we cant convert into wide string using the following code wstring widestring = std::wstring(str.begin(),str.end());

  2. The other approach is to use MultiByteToWideCharArray().

What i wanted to understand was what is the drawback of using the first approach and how does the second approach solves thing problem

like image 772
Siddharth Sarda Avatar asked Dec 15 '25 10:12

Siddharth Sarda


1 Answers

MultiByteToWideChar offers more options(like the ability to select "codepages") and translates non-standard symbols correctly

like image 52
P47RICK Avatar answered Dec 17 '25 00:12

P47RICK



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!