|
-
May 3rd, 2008, 10:31 PM
#1
Please help me in this code.... [ << I'm newbie]
#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.
-
May 3rd, 2008, 10:50 PM
#2
Re: Please help me in this code.... [ << I'm newbie]
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.
Can you help me with my homework assignment?, Before you post!, Use code tags, How to post!, Codeguru technical FAQs, C++ FAQ Lite, Stroustrup: C++ Style and Technique FAQ, Guru of the Week, Comeau C and C++ FAQs, Comeau C++ Templates FAQs, CUJ @ DDJ, Spam threshold
My Blogs : Learning C++ is fun | Abnegator's reflections
Open Threads : C++ Aha! Moments | Nature of work in C++?
-
May 4th, 2008, 02:35 PM
#3
Re: Please help me in this code.... [ << I'm newbie]
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/...ngInCPP2e.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++.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|