Sunday, March 09, 2008 4:22 PMWhy do you put an L in front of strings in C++?
Sunday, March 09, 2008 5:17 PM
The L prefix denotes a wide character/string literal; i.e., it is of type wchar_t instead of char. Unicode based programs typically use wide strings, while ANSI/ASCII based programs typically do not.
In Windows programs, you typically do not use L directly as a character/string prefix, but rather you use the _T() macro. _T emits an L prefix if Unicode is defined. See http://msdn2.microsoft.com/en-us/library/c426s321.aspx for more information.
Sunday, March 09, 2008 5:21 PMOk, thanks for that. So should I use it with all my strings?
Sunday, March 09, 2008 5:37 PMThere is no harm in always using TCHAR, _T, LPTSTR, LPCTSTR, etc. They incur no runtime overhead, and make it a great deal simpler if you ever want to change between building your project in Unicode vs non-Unicode. If your project is definitely only going to be ANSI or Unicode, and never change for the forseeable future, then there's no point in using the tchar macros, but again, there's no harm either.