-1
#include <codecvt>

Since codecvt deprecated in C++17, I need solid way to convert wstring to basic string.

Emily Janson
  • 25
  • 1
  • 5
  • Perhaps tehre is some useful information for you here: https://stackoverflow.com/questions/402283/stdwstring-vs-stdstring – andres Jan 10 '19 at 02:46
  • 1
    This is not relevant, im not asking difference of these variables – Emily Janson Jan 10 '19 at 02:59
  • 1
    How about this: https://stackoverflow.com/a/4805413/2898736 – andres Jan 10 '19 at 03:03
  • 1
    Possible duplicate of [How to convert wstring into string?](https://stackoverflow.com/questions/4804298/how-to-convert-wstring-into-string) – andres Jan 10 '19 at 03:04
  • C++ standards are still struggling with unicode. The failure of codecvt and its deprecation is an example. Since wstring can be of several different widths, depending upon the operating system, this is complex. I ended up using the ICU library to handle this issue. – rsjaffe Jan 10 '19 at 03:36
  • The ICU library (http://site.icu-project.org/home) may be like using a sledgehammer on a gnat, but it definitely works. If you can afford the overhead, it's a good solution. – rsjaffe Jan 10 '19 at 03:38
  • [Boost.Locale](https://www.boost.org/doc/libs/release/libs/locale/doc/html/charset_handling.html) as a more lightweight approach than ICU. I think it can even use ICU as a backend, should the need arise. – zett42 Jan 11 '19 at 21:05

2 Answers2

1

"Deprecated" does not mean "removed". It means that it may be subject to removal in a future C++ standard. Feel free to use it for the time being. C++20, for example, still has <codecvt> around. And the standard's committee seems to have decided that they're only going to proceed with removal once they have something to replace it.

Nicol Bolas
  • 449,505
  • 63
  • 781
  • 982
0

Windows-specific solution would be to use WideCharToMultiByte.

Alex Guteniev
  • 12,039
  • 2
  • 34
  • 79