470,580 Members | 2,176 Online
Bytes | Developer Community
New Post

Home 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

213 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.

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.
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.

A work around to get past "to_wstring is not a member of std" .
Dec 29 '20 #1
3 2859
9,208 Expert Mod 8TB
Where is your

#include <string>

Dec 29 '20 #2
213 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.
Dec 30 '20 #3
213 128KB

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.
Jan 1 '21 #4

Post your reply

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
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.