string usage

Last time, I was in "Anton And Danik" in part to introduce the use of string

Today, I come to tell you about the string of other usage:

(There may have been talked about, do not mind)

1 Definitions

Suppose you want to define a string variable name is s, then the same definitions as the following:

string s;

Moreover, the string can be defined like an array:

#define maxn 100010//定义元素个数的最大值,这里 maxn 为 100010
string s[maxn];

Or directly

string s[100010];

2. Enter

There are two ways to enter the input mode is not the same.

getline\color{orange}\text{getline}getline

getline \ Color Red {} \ {text} getline getline this embodiment is able to input the input space

Its implementation is as follows:

getline(cin,字符串变量名);

cin\color{blue}\text{cin}cin

CIN \ Color Green {} \ {text} CIN CIN is the input mode getline Color Gold {} \ {text} getline \ getline contrary, it can not be read into the spaces

Therefore, it is implemented as follows:

cin>>字符串变量名;

Here with digital input, the characters are the same

3. Output

Here is very simple, as long as  cout \ Color {Pink} \ {text} cout  cout on the line

(Can only be used and  COUT \ Color Purple {} \ {text} COUT  COUT)

cout<<字符串变量名;

4. The measuring string length

This knowledge is extremely important! !

String length is the length of the string.

Here, there are two string length measurement tool quietly emerged:

size\color{red}\text{size}size and\color{white}\text{and}and length\color{blue}\text{length}length

So, how you should measure it?

For convenience, we first define string string called s:

s.size();//用size测

s.length();//用length测

5. member functions

This is a need to focus on knowledge points to remember!

Let's turn to introduce these functions:

As the landlord lazy, these should be out next week

Guess you like

Origin www.cnblogs.com/SeashellBaylor/p/11079463.html