-
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?
-
>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.
-
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?
-
>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.