Click here to Skip to main content
15,911,531 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi,
Please describe (in simple words) the difference between char and widechar and char and wchar and wchar_t.
I explored the internet but cannot find satisfactory answer.
Posted

This might be of interest:
Character encoding[^]

Best regards
Espen Harlinn
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 3-Oct-11 20:33pm    
Good link, my 5.
--SA
Espen Harlinn 4-Oct-11 4:16am    
Thank you, Sergey!
Simon Bang Terkildsen 4-Oct-11 2:26am    
+5
Espen Harlinn 4-Oct-11 4:16am    
Thank you, Simon!
char - 1 byte
wchar_t - 2 bytes
wchar not a C++ type
 
Share this answer
 
Comments
ahsanriaz1K 3-Oct-11 3:38am    
and what is the difference in functionality?
Simon Bang Terkildsen 3-Oct-11 3:44am    
? char can contain one byte of data while wchar_t can contain two. Thus char is used for ascii characters while wchar_t is used for unicode characters.
Espen Harlinn 3-Oct-11 17:57pm    
Good answer :)
Sergey Alexandrovich Kryukov 3-Oct-11 20:41pm    
My 4 this time. As you mentioned Unicode, it would be good to note that Unicode is no way a 16-bit code. It would needs some paragraph to explain what is it. In C++ standard (or just in Stroustrup book) there is a special note that 16-bit character does not impose any assumption about the character set used. This is more or less wise. Let's take Unicode presented using 16-bit characters. Usually (Windows, .NET. Mono, Linux and more) it means that the used encoding is either UTF16LE or UTF16BE. These encodings require that a Unicode character outside BMP (see http://www.Unicode.org) are represented with surrogate pairs. So, some characters are represented by one 16-bit word, but some are with two words, which needs special care when characters are counted, copies, etc. At the same time, "normal" string manipulations may remain completely agnostic to this complication.
--SA
Simon Bang Terkildsen 4-Oct-11 2:20am    
Thank you for the vote. Very true I should probably have talked about that, though you mention surrogate pairs which I actually have no idea what is, so this has been put on my todo list, as I clearly lack some information on this.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900