Click to See Complete Forum and Search --> : Please help me in this code.... [ << I'm newbie]


nnvkct
May 3rd, 2008, 10:31 PM
#include "stdafx.h"
#include <iostream>

int main()
{
wprintf(L"%c", L'abc');
return 0;

--------------------------------------
Can you explain me the meaning of 'L' in string L"%c" and L'abc'. What's the different from using wprintf and printf?

Thanks in advance. I'm grateful any help.

exterminator
May 3rd, 2008, 10:50 PM
Easiest way to find such stuff out is to search for the documentation. You can get it over the web from a variety of places, one being msdn.

The 'L' prefix is used to denote that the following string or character is a wide string/character literal. For simplicity, you can consider that wide characters are different from characters in the storage required. char fits into 1 byte but wide chars need more than 1 byte to store the character. To work with wide characters/strings, you need to work with function that know what wide chars are - printf probably doesn't know, but wprintf knows and work the same way printf works with normal characters.

tom voss
May 4th, 2008, 02:35 PM
exterminator pretty much answered your questions I believe. Wide characters are used to store foreign characters, etc., and is a superset of the standard ASCII character set.

Is there any reason for you to be using a wide character set? Also as an aside, typically in C++ cout is used for formatted output. (That's not to say there's anything wrong with printf, but you should be aware of cout and should probably use cout if you have no specific reason to use printf.)

Also, you may want to check out http://www.mindview.net/Books/TICPP/ThinkingInCPP2e.html if you don't already have some sort of C++ book to guide you (this is a freely available electronic copy of a C++ book - you can download it legally ;-)). Also, http://www.cplusplus.com/reference/ is a great place to figure out syntax.

C++ is a great language - though perhaps not intended to be "newbie-friendly" language it is very powerful and for the purposes of in-depth learning gives enough of a "high level" and a "low level" view into programming that it's easy to pick up most other languages afterwards. Anyway, I'm getting off topic, but good luck and have fun exploring C++.