Thread: Help with tchar

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

    Help with tchar

    I'm a Computer Science major at a small university that teaches C++. Recently I've started to do some research on my own, because I don't believe my university is teaching me everthing I need to know and I came across tchar. What and how do you use tchar? I tried searching but I couldn't fine much information and when I tried to use tchar in a program I got undefined variable and usee I did include the header file tchar.h. Thanks for your help.

  2. #2
    Registered User
    Join Date
    Aug 2005
    Posts
    1,267
    TCHAR is a macro that translates to wchar_t when the program is compiled for UNICODE and char when not. Its defined in tchar.h. A wchar_t is a UNICODE wide character designed to hold characters of most languages, such as English, Spanish, Chines, Japanese, etc. Characers of many of those languages cannot be represented in an 8-bit char, so UNICODE designed wchar_t, which may be defined as unsigned short on some operating systems or unsigned long on others. Google for UNICODE and you should find a lot of information.

  3. #3
    Registered User
    Join Date
    Apr 2006
    Posts
    38
    Thanks but how would I go about using tchar? I'm really not sure about macros because I've never done anything with macros.

  4. #4
    Lurking whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    9,612
    You would still have to do some research (to find out how to use all the macros in tchar correctly) but macros in general work with the preprocessor directive #define MACRO_NAME value. You then can use the phrase MACRO_NAME through out your program. At compile-time the compiler substutes the text for the value.
    Last edited by whiteflags; 04-25-2006 at 09:54 PM.

  5. #5
    Registered User
    Join Date
    Aug 2005
    Posts
    1,267
    Ok -- here's an example -- note the spelling and capatalization -- it is TCHAR, not tchar.
    Code:
    TCHAR hello[] = _TEXT("Hello World");

  6. #6
    Registered User
    Join Date
    Apr 2006
    Posts
    38
    Quote Originally Posted by Ancient Dragon
    Ok -- here's an example -- note the spelling and capatalization -- it is TCHAR, not tchar.
    Code:
    TCHAR hello[] = _TEXT("Hello World");
    Thanks. I saw that example earlier on the web and it still gives me undefined. I've even copied and pasted the example.

  7. #7
    Tropical Coder Darryl's Avatar
    Join Date
    Mar 2005
    Location
    Cayman Islands
    Posts
    503
    you need to include tchar.h

  8. #8
    Registered User
    Join Date
    Apr 2006
    Posts
    38
    Quote Originally Posted by Darryl
    you need to include tchar.h
    Read man I did use the include tchar.h file. Sorry, but people who refuse to read a post just irritates me.

  9. #9
    Registered User
    Join Date
    Aug 2005
    Posts
    1,267
    Quote Originally Posted by dnysveen
    Read man I did use the include tchar.h file. Sorry, but people who refuse to read a post just irritates me.

    well then try posting your program. people who complain without posting any code irritate me too.

    This works with VC++ 6.0, although TCHAR will be defined as char* unless _UNICODE is also defined before including tchar.h
    Code:
    #include <tchar.h>
    
    int main(int argc, char* argv[])
    {
    	TCHAR hello[] = _TEXT("Hello World");
    	return 0;
    }
    Last edited by Ancient Dragon; 04-26-2006 at 10:18 AM.

  10. #10
    Registered User
    Join Date
    Apr 2006
    Posts
    38
    Quote Originally Posted by Ancient Dragon
    well then try posting your program. people who complain without posting any code irritate me too.

    This works with VC++ 6.0, although TCHAR will be defined as char* unless _UNICODE is also defined before including tchar.h
    Code:
    #include <tchar.h>
    
    int main(int argc, char* argv[])
    {
    	TCHAR hello[] = _TEXT("Hello World");
    	return 0;
    }
    I didn't post code because there was no code besides the code I posted. I used include file and then declared a TCHAR. Of course I used a main and return 0 but I didn't think you needed to see that

    Updated. I copied and pasted your code and its a no go. I'm using the borland compiler for C++

  11. #11
    Registered User
    Join Date
    Aug 2005
    Posts
    1,267
    >>I'm using the borland compiler for C++

    well that pretty much sums up the problem -- throw that cr@p away . Check its tchar.h file and see if it needs some other macro defined, such as _UNICODE. The compiler's preprocessor may be ignoring tchar.h entirely.

  12. #12
    Registered User
    Join Date
    Apr 2006
    Posts
    38
    Quote Originally Posted by Ancient Dragon
    >>I'm using the borland compiler for C++

    well that pretty much sums up the problem -- throw that cr@p away . Check its tchar.h file and see if it needs some other macro defined, such as _UNICODE. The compiler's preprocessor may be ignoring tchar.h entirely.
    What free complier would you suggest? I've never had any problems with the borland compiler. Is there a reason you think its crap, besides tchar?

  13. #13
    Sweet
    Join Date
    Aug 2002
    Location
    Tucson, Arizona
    Posts
    1,820
    There is nothing wrong with BC++ Ancient Dragon is being a bit bias. I would say that you do not need to concern yourself with wchar_t unless you are planning for your programming to used in mulitple languages.
    Woop?

  14. #14
    Registered User
    Join Date
    Aug 2005
    Posts
    1,267
    Quote Originally Posted by dnysveen
    What free complier would you suggest? I've never had any problems with the borland compiler. Is there a reason you think its crap, besides tchar?
    You didn't answer my question (or statement) -- did you look at your copy of tchar.h to see why it doesn't recognize TCHAR macro?

  15. #15
    Registered User
    Join Date
    Apr 2006
    Posts
    38
    Quote Originally Posted by Ancient Dragon
    You didn't answer my question (or statement) -- did you look at your copy of tchar.h to see why it doesn't recognize TCHAR macro?
    I didn't look at my tchar.h file because I haven't had the chance, I'm sorry its been less than a day since you asked and I'm studying for files.

    I'm interested in tchar because I want to get a job with Microsoft. I've been doing a lot of research and watched a Microsoft recruiting video and in their interview question they expected the person to know how to use tchar.

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