Method 1:
Method 1: For Beginners, modify the encoding format in vs2010:
Right-click the project --"
Select "Properties" --"
Select "Configuration Properties" --"
Select "General" --"
Finally, change "Character Set" under "Project Default" to "Use Multi-Byte Character Set" ("Use Unicode Character Set" by Default ")
This saves a lot of time for converting the type display. But this is not good for learning windows, because it cannot understand the features of windows Programming and the principles of character formats. If you have the energy, please do not use method 1. If you have more efforts, please refer to methods 2 and 3. You will learn a lot. This is the case for learning programming. Do not covet yourself and be sure to avoid suffering. If you encounter any difficulties, try your best to understand:
1. Why is this error?
2. How can this error be solved?
3. which method is the best? Why?
4. Lenovo has encountered similar problems, such as comparison, consideration, and summary.
I believe you will go further.
Method 2:
Method 2: # include <tchar. h> must be introduced before TEXT can be used for conversion.
- LPCWSTR str1 = TEXT ("Hello ");
- LPCWSTR str2 = L "Hello ";
- LPCWSTR str3 = _ T ("Hello ");
Method 3:
This is a solution for storing strings using variables.
- Const char * ch = "Hello ";
- WCHAR wCh [6];
- MultiByteToWideChar (, ch, 5, wCh, 6); // for usage of the MultiByteToWideChar function, see MSDN
- LPCWSTR str4 = wCh;