Ask why bosses, these three output is completely different! Change it to the char array is a step in the right, isn't me to the use of string have any misunderstanding! Still hope bosses give advice or comments about
CodePudding user response:
https://zh.cppreference.com/w/cpp/string/basic_string/operator_at
Pay attention to the string [] overloading of crossing the line is undefined behavior
Here all your string is an empty string
Mp [0] is null bytes reference
Mp [1] is undefined behavior
CodePudding user response:
reference 1st floor lin5161678 response: https://zh.cppreference.com/w/cpp/string/basic_string/operator_atPay attention to the string [] overloading of crossing the line is undefined behavior Here all your string is an empty string Mp [0] is null bytes reference Mp [1] is undefined behavior Not understand, what should do CodePudding user response:
refer to the second floor Anterior_condyle response: not understand, what should do? It opens at CodePudding user response:
Mp is not a one-dimensional array CodePudding user response:
reference 4 floor qq_46221910 response: mp is not a one dimensional array A string array of two-dimensional you can write the CodePudding user response:
You said that you define a string array, but each string object has not yet been element in an array, how is it possible to visit you? You have to initialize this string array In simple terms, if you have identified your most length of each string such as: 100, the string strArray [100]. for(int i=0; i<100; + + I) { StrArray [I]. Resize (100); } CodePudding user response:
refer to 6th floor donwmufromdying response: you said that you define a string array, but each string object has not yet been element in an array, how is it possible to visit you? You have to initialize this string array In simple terms, if you have identified your most length of each string such as: 100, the string strArray [100]. for(int i=0; i<100; + + I) { StrArray [I]. Resize (100); } Ha ha, seems to be the truth, why shouldn't the char type two-dimensional array need to initialize the can direct assignment! CodePudding user response:
String and char [] is two different things, a class of string type, char [] a simple type, char [] declares the memory is allocated, string, the string of the actual internal memory are allocated on the heap, is completely different