Sorry. Did you want it back?
Σnigma
I am ashamed. C++ simple question [resolved]
Alright, thanks for the tip; I'll give the VS9 compiler a try.
In the meantime, since ASCII is a subset of UNICODE, I've got the following bit of code in-place to do the conversion. A little dirty, but it works.
In the meantime, since ASCII is a subset of UNICODE, I've got the following bit of code in-place to do the conversion. A little dirty, but it works.
basic_stringstream<char> buffer;buffer << fps << " fps";size_t len = buffer.str().size();basic_string<wchar_t> text(len, '?');for(size_t i = 0; i < len; i++) text.at(i) = buffer.str().at(i);
Quote:Original post by Wyrframe
Alright, thanks for the tip; I'll give the VS9 compiler a try.
In the meantime, since ASCII is a subset of UNICODE, I've got the following bit of code in-place to do the conversion. A little dirty, but it works.
*** Source Snippet Removed ***
This recent thread may also be of some use to you.
As for your loop... several things stand out. Calling .at() is a range-checked version of the [] index operator. If the length of your string is constant (as is the case here) .at() isn't necessary given your loop condition. Also stringstream::str() returns a temporary string. In you're loop, you're constantly constructing a temp string (not cheap) and then making another needless .at() call on it.
Your loop should look like:
basic_stringstream<char> buffer;buffer << fps << " fps";string strBuffer(buffer.str()); // construct string once onlyconst size_t len = strBuffer.length();wstring text;wstring text.resize(len);for(size_t i = 0; i < len; ++i){ text = strBuffer; // both indices safe, i is always in the valid range 0 <= i < length}
or better yet, no loop at all:
wstring text;wstring text.resize(strBuffer.length());text.assign(strBuffer.begin(), strBuffer.end());
of course the whole thing should just look like this anyhow:
ostringstream buffer;buffer << fps << " fps";string strBuffer(buffer.str()); // construct string once onlywstring text(strBuffer.begin(), strBuffer.end());
[Edited by - godecho on June 9, 2008 10:26:42 AM]
It may be moot, as to do the conversion properly I'm now using...
basic_string<wchar_t> convToWString(basic_stringstream<char> & from) { basic_string<char> source = from.str(); int len = mbstowcs(NULL, source.c_str(), 0); if ( len == -1 ) { cerr << "[Invalid multi-byte character encountered]"; return basic_string<wchar_t> (); } wchar_t *buffer = new wchar_t[len]; mbstowcs(buffer, source.c_str(), len); basic_string<wchar_t> tmp(buffer, len); delete[] buffer; return tmp; }
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement