Cstring to char *, const char *
In C, it indicates a string. It does not have the string concept. Only char * and char [] can be used. In MFC, to serve string operations, a class cstring is added, the header file of this class is afx. h.The
Char ** P and const char ** P are two incompatible types, because they are two different types. If you understand this sentence, you don't have to read it.
First look at thisCode:
Code highlighting produced by Actipro CodeHighlighter
Copy Code code as follows:
char* get_str (void)
{
Char str[] = {"ABCD"};
return str;
}
Char str[] = {"ABCD"}; defines a local character array, although it is an array, but it is a local variable, and returning its address
This is one of the questions I have answered.This problem is a deep pit in C, first of all to say the conclusion:char * * and const char * * are two incompatible (incompatible) types, which can be understood as not being directly assigned to a
Conversion of String, char *, char[] in C + +One, the string to turn char*.There are three main ways to convert str to char* type: data (); C_str (); Copy ();1.data () method, such as:1 string str = "Hello"; 2 const char* P = str.data ();//Plus
(1) Overview
String and cstring are both string template classes. string is a string class defined by the standard template class (STL) and has been incorporated into the C ++ standard;
Cstring (typedef cstringt> cstring) is the most common
One, the string to turn char*.There are three main ways to convert str to char* type: data (); C_str (); Copy ();1.data () method, such as:1 string str = "Hello"; 2 const char* P = str.data ();//Plus const or char * p= (char*) str.data (); formAt
Comparison of cstring, string and char *
(1) Overview
String and cstring are both string template classes. string is a string class defined by the standard template class (STL) and has been incorporated into the C ++ standard;
Cstring (typedef
(1) Overview
String and cstring are both string template classes. string is a string class defined by the standard template class (STL) and has been incorporated into the C ++ standard;
Cstring (typedef cstringt> cstring) is the most common string
String and cstring are both string template classes. string is a string class defined by the standard template class (STL) and has been incorporated into the C ++ standard;
Cstring (typedefCstringt> cstring) is visualC ++ is the most common string
In C, it indicates a string. It does not have the string concept. Only char * and char [] can be used. In MFC, to serve string operations, a class CString is added, the header file of this class is afx. h.The conversion from char * To CString is
Where can I find the source?
Char * c = "ABC" and char C [] = "ABC", where the former changesThe program crashes, and the latter is completely correct.Program Demonstration:Test Environment devc ++Code# Include Using namespace STD;Main (){Char * C1 =
The prototype of the string function is char * strcpy (char * strdst, const char * strsrc)
Char * strcpy (char * strdst, const char * strsrc) // use const to indicate that the original string cannot be changed. In addition, use const to indicate
Char * P = "ABC" is different from Char P [] = "ABC"Problem introduction:During the internship, a default error was found, which is also char * c = "ABC" and char C [] = "ABC". The former changes the default error.The program crashes, and the latter
Oracle defines string types VARCHAR2 and char specify the length of the usage as follows:VARCHAR2 ( ) is a number between 1~4000 that represents up to 4000 bytes of storage space.char ( ) is a number between 1~2000 that represents up to 2000 bytes
Question:It is known that the prototype of the strcpy function is:Char * strcpy (char * strdest, const char * strsrc );1. Implement the strcpy function without calling the library function.2. Explain why char * is returned *.
Explanation:1.
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.