Thread: tChar

  1. #1
    Registered User
    Join Date
    Apr 2006
    Posts
    47

    tChar

    I'm trying to improve my C++ skills and I came across tChar? I did a search on tChar but could not find much information. If I understand correctly tChar works with both 16bit Unicode and 8 bit strings. This helps make the application more portable. Am I correct about the above two statements? So if its better should a tChar generally preferred over a string? What are the function associated with tChar? If you have a link to a guide that would be great. Thanks

    Edit*
    I have one other question. Why do most people prefer to use a pointer to traverse a string rather than indexing like an array?
    Last edited by BENCHMARKMAN; 09-30-2006 at 06:26 AM.

  2. #2
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,897
    >I did a search on tChar but could not find much information.
    It's a macro that chooses between char and wchar_t depending on the setupf of the application. For example:
    Code:
    #ifdef UNICODE
    #define TCHAR wchar_t
    #else
    #define TCHAR char
    #endif
    >Why do most people prefer to use a pointer to traverse a string rather than indexing like an array?
    It depends. Most of the time it's a misplaced belief that pointers are faster than indices. Some people prefer pointers out of habit, and some find them to be clearer. In C++, pointers are generally preferred because they can be used as iterators (and thus take advantage of the standard library) while indices cannot.
    My best code is written with the delete key.

  3. #3
    Registered User
    Join Date
    Apr 2006
    Posts
    47
    Thanks. So is tChar generally used over regular char's?

    What are the standard library you are talking about? I know about vectors but how could you use an iterator for a string with a vector. I know you can move to the next position in a vector with the iterator but how does this effect whether you traverse a string with pointer or indices?

  4. #4
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,897
    >So is tChar generally used over regular char's?
    No, tchar is used by Windows programmers who can't make up their mind.

    >What are the standard library you are talking about?
    Look in the <algorithm> header. It uses iterators almost exclusively, and a pointer meets the requirements of an iterator.
    My best code is written with the delete key.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. My progress.. thnx to Cprogramming forumites
    By csonx_p in forum Windows Programming
    Replies: 6
    Last Post: 05-21-2008, 01:17 AM
  2. Avoiding Global variables
    By csonx_p in forum Windows Programming
    Replies: 32
    Last Post: 05-19-2008, 12:17 AM
  3. String types and conversions (TCHAR)
    By csonx_p in forum Windows Programming
    Replies: 3
    Last Post: 05-07-2008, 02:33 AM
  4. How to use FTP?
    By maxorator in forum C++ Programming
    Replies: 8
    Last Post: 11-04-2005, 03:17 PM
  5. Tchar and %s %S
    By MiamiCuse in forum C Programming
    Replies: 1
    Last Post: 10-22-2005, 09:54 PM