unicode to string array

I need to initialize array of English and Geramn alphabets. The German alphabets has the unicode as follows: 00C01C(U_double_dot), 00C004 (A_double_dot), and 00C016(O_double_dot).

1
2
string mystr[] = {"A", "B", ..."Z"};
string myGERstr[] = TBD


How to convert from unicode to string in this case? Any help will be appreciated.
Last edited on
Let me get this straight. You're trying to use unicode characters in a string constant, is that right?

If so, I recommend "\xhhhh" where h is a hexadecimal digit, using the last four digits.


EDIT: Slow day. Ignore this.

-Albatross
Last edited on
That won't work, as that will store them in UTF-16 format when the actual string is (likely) UTF-8

The easiest way would be to just have your text editor save the file as UTF-8 and type the characters into the source the same you you type normal English characters.


The problem is, other libraries don't necessarily know how to output UTF-8. You can store the data in the string any way you like, but if the library doesn't know how to use it then it won't work.

The real question here is what do you want to do with these strings once you have them?
Idiot me. Of course, strings are a typedef of a basic_string<char>. Plus it doesn't help that indeed Unicode characters sometimes are tricky to get to print out properly (depending on the library and the platform, iirc).

Yeah, today is definitely a slow day for me.

-Albatross
Last edited on
I am just going to use the German character and output as a keypad. How to type the German character using visual studio or other IDE editor?
Copy and paste from an editor you know how to type the character in? Just an idea.

-Albatross
I am just going to use the German character and output as a keypad


But how are you outputting?

If your plan is to output to the console on Windows, you're in for a nasty surprise.
hello ,

you can use wcrtomb to do this conversion
wctomb just converts a "wide" character to a "multibyte" character. Strangely enough, both of those terms are somewhat meaningless as they aren't necessarily related to Unicode.

What's more, outputting wide characters to wcout or (multibyte characters to cout) doesn't even necessarily work. It depends on system locale settings and other factors.

There's not even any guarantee that the font the terminal you're using has the characters you want to output, so even if the output is correct, you might get one of those 'invalid character boxes'.


There's really no simple answer to this question, especially since we still don't know how coder1998 is trying to output. In order for us to give him a complete solution, he'll need to be more specific about what he wants.
Last edited on
Disch +1. Even on some Mac OS X consoles one can be in for a nasty surprise. We need to know more about what you wanna do, coder1998.

-Albatross
I am writing the following code and the compiler has no complain on these. will let you all know the progress soon.

1
2
3
4
 
 myGERstr[0] = L"Ä";          
 myGERstr[1] = L"Ö";        
 myGERst6[2] = L"Ü";        


Thanks
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
#include "stdafx.h"
#include <string>
#include <iostream>

using namespace System;
using namespace std;

int main(array<System::String ^> ^args)
{

            string s[] = { "A", "B", "C" };
            string s1[]= { "Ä", "Ö", "Ü" };

            cout << s[0] << endl;    cout << s[1] << endl;     cout << s[2] << endl;
            cout << s1[0] << endl;  cout << s1[1] << endl;    cout << s1[2] << endl;  
            return 0;
}


I am using Visual Studio 2008, the output for A, B, C is correct, however it does not produce German character Ä, Ö, and Ü as many of you pointed out, any suggestion?
So you found your 'nasty surprise'...

You must keep in mind the character set (or code page) for your output. like any charachter set contains german umlaut.

Here is a microsoft list of code pages: http://msdn.microsoft.com/en-us/goglobal/bb964653.aspx

For the console I think it's code page 437. Visual Studio can save sources accourding this and several other code pages.
Topic archived. No new replies allowed.