467,074 Members | 953 Online
Bytes | Developer Community
Ask Question

Home New Posts Topics Members FAQ

Share your developer knowledge by writing an article on Bytes.

to_wstring is not a member of std (A work-around) C++11

SwissProgrammer
128KB
Not .net anything.
Not Visual Studio anything.

In a C++11 program I intend to use Unicode and wstring and wchar_t. I am doing some bit parsing and bit manipulations for something and I want to have some results of that parsing in wstring or wchar_t. Thus, I want to put the 0's and 1's from some process into a wstring.

Example:
The Binary of [办] is [101001010011110].
I can input 办 and I can get 101001010011110.
I can parse into bits the 101001010011110 and do things with the result.
But,
I want to see the result in wstring.


Here is a test example:

If I used:
wstring x;
and if I tried to then use:
x = std::to_wstring(101001010011110);
I received an error similar to:
to_wstring is not a member of std
The problem seems to be in my compiler.
I do not want to change my compiler.

I chose that compiler for specific reasons and I intend to use that particular compiler. Therefore I needed a work around for going from a number (1010101010) to a wide string. In this case, the number is ASCII.

So, I am going from ASCII to a string to a wide string.

The following is an actual part of my code that does work.
With notes.

Expand|Select|Wrap|Line Numbers
  1.     int ix = 1010101010;
  2.     std::string f_str = std::to_string(ix);     // From int to wstring is not working with std::to_wstring on this compiler even though it is set to C++11
  3.                                                 //    therefore going from int to string then from string to wstring.
  4.     wstring wstr (f_str.begin(), f_str.end());  // Since it starts with an integer, which is in ASCII then
  5.                                                 //    since this only works well if the string being converted contains only ASCII characters
  6.                                                 // Therefore, it is OK to use here.
  7.  

A work around to get past "to_wstring is not a member of std" .
2 Weeks Ago #1
  • viewed: 1699
Share:
3 Comments
weaknessforcats
Expert Mod 8TB
Where is your

#include <string>

?
2 Weeks Ago #2
SwissProgrammer
128KB
Thank you.

I might have pointed out, more clearly, that this post is about just a little part of the entire program where I changed it to work around a difficulty. With some explanations.

Mostly I wanted to post this since I had searched a lot for how to force a compiler to do as I desired even if it has difficulty and tells me "to_wstring is not a member of std". I looked and did not find any other satisfactory fix for that problem. This does not use "to_wstring". It works with my compiler (GNU GCC) that I received along with Code::Blocks 17.12, which I have been told does use "to_wstring" (which it seems to not use for me). But it works.

Elsewhere in the code is #include <string> along with lots of other stuff.

This is just a "part of my code" where I was talking about a change in it.

At your level of experience, I expect you to probably know a better way to fix this via code only (without changing my compiler). But, in my searching I did not find even this much of a way to fix this. So, here it is.

Thank you weaknessforcats.
2 Weeks Ago #3
SwissProgrammer
128KB
weaknessforcats,

Thank you.

I now realize that you were helping me in how to post usefully.

I gave you excuses.

I should have just said thank you and included the code in my post.
2 Weeks Ago #4

Sign in to post your reply or Sign up for a free account.

Similar topics

reply views Thread by Shailesh | last post: by
6 posts views Thread by Mike Alexeev | last post: by
7 posts views Thread by Srini | last post: by
9 posts views Thread by tropostropos@hotmail.com | last post: by
4 posts views Thread by Rubbrecht Philippe | last post: by
40 posts views Thread by Steve Rencontre | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.