Summary CString, String, char*

Source: Internet
Author: User
(i) First of all, string and char*: 1, overview 2, the reciprocal transformation of the two: (ii) CString 1, overview 2, CString and the other two transformations (a) First, string and char*: 1. Overview

In the C language:

1 String is a string, and char* is a character pointer. The two are not equal at any time, and when the address of the character pointer holds a string (that is, a sequence of characters at the end of ' a '), it can be said to point to a string that is not equivalent in other cases.

In C + +: string is a character container, which is an extended template class in the template library, and char is a basic data type (the built-in type of C + +), which is even less equivalent. Where string has a constructor, Char has no constructor and can only be assigned a value (char* m= "abc"; String str (m);) 2, the reciprocal transformation of the two:

String to char*:

1 Use the C_str () method. ' std::string str= ' "abc"; char* p=str.c_str (); '

char* to String:

1 Use the initialization string s (char *) directly, preferably using assign () where it is not initialized;
(ii) CString 1. Overview

CString is a very useful type of data. They largely simplify many of the operations in MFC, making it much easier for MFC to do string manipulation. One aspect of the CString type convenience feature is the connection of strings, with the CString type, you can easily connect two strings, as in the following example:

1 CString Gray ("gray");

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.