Console console using MFC library functions, cout output CString method

Source: Internet
Author: User

When new project is selected: Win32 Console application

Check the MFC header file support in the wizard to confirm

After you wait for the initialization file to complete, VS2010 automatically opens the project name. cpp File

where int _tmain (int argc, tchar* argv[], tchar* envp[]) This corresponds to the main function

All the contents can be deleted, and finally add a return 0;

MFC common classes: CString class

If you use VS2010, you may see CStringT, which is actually a template class that operates on variable-length strings . The CStringT template class has three instances: CString, CStringA, and CSTRINGW, which provide operations for strings of TCHAR, Char, and wchar_t character types, respectively.

The char type defines ANSI characters, the wchar_t type defines Unicode characters, and TCHAR depends on the configuration of the MFC Project's Properties dialog box properties->general-> Character the Set property, if this property is use Multi-Byte Character set, the TCHAR type defines the ANSI character, and if it is use Unicode Character set, The TCHAR type defines a Unicode character.

Let's look at an example below:

int _tmain (int argc, tchar* argv[], tchar* envp[]) {CString str1 (_t ("www.jizhuomi.com")),//wcout << str1. GetString () << endl;cout << str1. GetString () << Endl;return 0;}

The code above creates a CString object based on the string,

How to Output CString

Because it is wide character, so with Wcout

Because CString is essentially a pointer, and the operator << does not overload the output of CString, the GetString () member function with the CString comes in.

Wcout < <cpath. GetString () < <endl;

  

The operation of three string classes is the same, except that the character types are handled differently. Chicken Peck Rice to CString class for the explanation object.

Console console using MFC library functions, cout output CString method

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.