First of all, I am a vegetable force, this problem only found today, only to understand what is meant;;;
Programming Daniel Please ignore this article,,, for beginners to exchange experience it;;;;
Near the final exam, and took out the water before doing a glance, exultation, and found the problem;;;
In the previous C language, we would often use char to define a character or string,
When dealing with string lengths, string comparisons usually add a header file #include <string.h> yes;;;
Now, in C + +,,, there's also a #include <string>;
It puzzled me that I did not think about the problem, and that,
In fact, in C + + #include the header file in the <string> representation of the thing template (STL), then in C + +;
Always like to use string to define strings;;;;;;
Today we finally understand his advantages, please look at the following code:;;;;
#include <iostream>
#include <string>
#include <algorithm>
using
namespace
std;
int
main()
{
string s[50005];
int
T,i=0,j=0;
cin>>T;
while
(T--)cin>>s[i++];
sort(s,s+i);
while
(i--)cout<<s[j++]<<endl;
}
The code is simple, but it implements the dictionary order of the strings;;;;
In fact at that time in doubt string s[50005];;; What a ghost it is;
Everybody knows what they want to say.;; just define a two-dimensional array, and at first I think that string is just like char, which doesn't make sense;
To enter several sets of strings, but if it is understood as Char, it is defined only as a single string;
Now it really feels funny;;; it is the use of templates in C + +;;; The string is a special type of container because he is more of a data type than a container of ancient types-string;; can be like int, double, such as the basic data type, define the data of type string, and perform various operations.
So for the length of its string, it cannot be used strlen, because it is not the same thing, it needs to use the property in the String class;;;
As to length with string name.length (); or name.size ();;;;
About the other features of string,,,, ask degrees Niang,,,, not the focus of this article;;;;
C + + BASIC programming string