One L"..." string is interpreted as const char[2] - is C++ malfunctioning?
-
Saturday, February 25, 2012 9:23 AM
I tried using an array of all ASCII and Unicode charcaters (although I am only showing the ASCII table below) to be accessible via charmap[int_var], because
wchar_t[int_var]
does not work, unlike the regular way to find a character by code:
wchar_t[127]
However, there seems to be something wrong when parsing this code:
array<const wchar_t *> ^ charmap = {L"", L" ", L"!", L"\"", L"#", L"$", L"%", L"&", L"'", L"(", L")", L"*", L"+", L",", L"-", L".", L"/", L"0", L"1", L"2", L"3", L"4", L"5", L"6", L"7", L"8", L"9", L":", L";", L"<", L"=", L">", L"?", L"@", L"A", L"B", L"C", L"D", L"E", L"F", L"G", L"H", L"I", L"J", L"K", "L", L"M", L"N", L"O", L"P", L"Q", L"R", L"S", L"T", L"U", L"V", L"W", L"X", L"Y", L"Z", L"[", L"\\", L"]", L"^", L"_", L"`", L"a", L"b", L"c", L"d", L"e", L"f", L"g", L"h", L"i", L"j", L"k", L"l", L"m", L"n", L"o", L"p", L"q", L"r", L"s", L"t", L"u", L"v", L"w", L"x", L"y", L"z", L"{", L"|", L"}", L"~"};(error C2440: 'argument' : cannot convert from 'const char [2]' to 'const wchar_t *')
I know that that error happened when I tried to use a regular "C" instead of L"C" in the array, but for some readon, it is happening even with all L"" and no "" in the array. Is the compiler being Crazy++?
Update: Oh, the "L" instead of L"L" which my eyes did not look at in the first time. It's just a programmer's mistake here but I also told that, if you get that error, check for ""-style strings in the array<const wchar_t *> and replace them with L""-style strings.
- Edited by Rohan Pai Saturday, February 25, 2012 9:39 AM
All Replies
-
Saturday, February 25, 2012 9:32 AM
Look carefully at the letter L in your array:
L"H", L"I", L"J", L"K", "L", L"M", L"N",
- Wayne
-
Saturday, February 25, 2012 9:33 AMLook at the string for capital L.
This is a signature
Any samples given are not meant to have error checking or show best practices. They are meant to just illustrate a point. I may also give inefficient code or introduce some problems to discourage copy/paste coding. This is because the major point of my posts is to aid in the learning process.

