Thread: Adding two strings to make a wchar_t

  1. #1
    Registered User
    Join Date
    Dec 2004
    Posts
    73

    Adding two strings to make a wchar_t

    I need to combine "Missing Program File" and a char variable to make an LPCTSTR, which is a Windows typedef to a wchar_t. Also, what is the difference between char and wchar_t? Why can't you interchange them?

  2. #2
    Registered User Kybo_Ren's Avatar
    Join Date
    Sep 2004
    Posts
    136
    Char is one byte, while wchar_t is 2 bytes.

    Char, when used for strings, *generally* uses the ASCII character set, while wchar_t *generally* uses the Unicode set.

    I think

  3. #3
    Registered User
    Join Date
    Dec 2004
    Posts
    73
    Okay, so how do I combine two wchar_t's into one?

  4. #4
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    You could just write your own. You do know what a loop is, right?

    Quzah.
    Hope is the first step on the road to disappointment.

  5. #5
    Yes, my avatar is stolen anonytmouse's Avatar
    Join Date
    Dec 2002
    Posts
    2,544
    Most of the C standard library functions are available in wide character versions. Include the header file <wchar.h>. Functions you may be interested in are wcscat and swprintf. Check out wchar.h for more functions.

    A C++ friendly solution is to use a wstring. This is the wide character equivalent of string.

    Another alternative are the safer string handling function in <strsafe.h>.

    >> LPCTSTR, which is a Windows typedef to a wchar_t <<

    Actually, a LPCTSTR is, by default, a const char*. If you define UNICODE before including any headers, it becomes a const wchar_t*. This allows you to write code that can be compiled as either unicode or ansi. If you don't care about supporting unicode, you can just treat a LPCTSTR as a const char*. There are TCHAR equivalent macros for the C standard library string functions in <tchar.h>.

    The Absolute Minimum Every Software Developer Absolutely, Positively Must Know About Unicode and Character Sets (No Excuses!)
    Last edited by anonytmouse; 01-23-2005 at 11:39 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. What to make?
    By Caldus in forum C++ Programming
    Replies: 4
    Last Post: 04-06-2005, 01:12 PM
  2. adding onto strings
    By Granger9 in forum C Programming
    Replies: 6
    Last Post: 09-11-2002, 01:06 PM
  3. Adding stuff to strings from files..
    By R@m0n in forum C++ Programming
    Replies: 4
    Last Post: 02-03-2002, 02:38 PM
  4. Adding to strings..
    By SyntaxBubble in forum Windows Programming
    Replies: 1
    Last Post: 10-25-2001, 04:22 PM
  5. array of strings + more
    By null in forum C Programming
    Replies: 10
    Last Post: 10-01-2001, 03:39 PM