Download here. string-wstring-conversion-functions
// Filename : string_wstring.cpp
// Author : A.G.Raja
// License : GPL
// Website : https://agraja.wordpress.com
#include <iostream>
using namespace std;
string wstring2string(wstring wstr) {
string str(wstr.length(),’ ‘);
copy(wstr.begin(),wstr.end(),str.begin());
return str;
}
wstring string2wstring(string str) {
wstring wstr(str.length(),L’ ‘);
copy(str.begin(),str.end(),wstr.begin());
return wstr;
}
int main() {
wstring wstr = string2wstring(“raja”);
string str = wstring2string(wstr);
cout<<str<<endl;
}
Pingback: C++ string, wstring conversion functions | Today's Bargain Electronics Store
Pingback: Business blog » Blog Archive » C++ string, wstring conversion functions
Hi, thats OK for words in english, but in spanish don’t. Try to convert: documentación, gané, or other word with á, é, í, ó or ú.
Bye.
Of course, you’ll abuse *your* privilege to refuse my comment, nevertheless I have rigth to convey the truth: this is just a crap in all aspects.
Do meditate on the following –
// this stuff is Public Domain 😀
std::wstring string2wstring(std::string & str) {
return std::wstring(str.begin(),str.end());
}
Though this does NO conversion (like yours) but at last with no overhead 😉
Nothing personal, I’m able to code even worse, but taking care no one can watch it. Please do not confuse teaching and learning.
WBR, Serge.