CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    May 2008
    Posts
    2

    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.

  2. #2
    Join Date
    Feb 2005
    Location
    "The Capital"
    Posts
    5,306

    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.

  3. #3
    Join Date
    May 2008
    Posts
    4

    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
  •  





Click Here to Expand Forum to Full Width

Featured