View Single Post
  #4 (permalink)  
Old 12-01-2007, 04:56 AM
Bench Bench is offline
Full Programmer
Join Date: Jul 2007
Location: UK
Posts: 116
iTrader: (0)
Bench is on a distinguished roadBench is on a distinguished roadBench is on a distinguished roadBench is on a distinguished roadBench is on a distinguished road
Not really - wide character strings aren't just a simple modification of adding L's to your program. you need to use the wide character string type and related I/O streams too.

There's no point in storing simple strings (eg, "hello") in wide character format - since not only does it complicate things (wchar_t has no standard defined size, and its representations vary), it usually uses more bytes than necessary too.

Internationalisation extends beyond wide characters into areas such as number representation, date representation, etc. The usual approach is to write the user interface portion separately, then only the UI will be concerned with these issues, allowing the rest of the program to continue internally without having to worry about how it looks to the outside world.

If you want to make a habit of using wchar_t for everything, then feel free. although the more common approach is a conversion function to widen or narrow strings as you need to. eg,
Code:
#include <iostream>
#include <string>
#include <locale>

std::wstring widen_string(std::string str)
{
    std::wstring result;
    std::locale loc;
    for(int i(0); i < str.size(); ++i)
    {
        result += std::use_facet<std::ctype<wchar_t> >(loc).widen(str[i]);
    }
    return result;
}

int main()
{
    std::string str = "hello, world";

    std::wcout << widen_string(str);
}

__________________

Digg this Post! Del.Icio.Us this Post! Technorati this Post! Furl this Post! Mister Wong this Post! Newsvine this Post! Spurl this Post! Reddit this Post! Netscape this Post!

Last edited by Bench : 12-01-2007 at 05:00 AM.
Reply With Quote
The Following User Says Thank You to Bench For This Useful Post:
HelloWorld (12-01-2007)