C + + BASIC programming string

Source: Internet
Author: User

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

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.