C + + Learning Note 12--string

Source: Internet
Author: User

String Class-- C + +-style string class,<string>

Constructor: string (const string& s), string (const char* s)

string (int N,char c);

Operator: <<,>>,=,+,+=,[] does not check out of bounds, the at (int) checks out, and the comparison operator <,<=,>=,>,==,!=

Length: Size (), length (), bool Empty (), resize (NEWSIZE,FILLC)

Convert to C-style: C_str (), data () does not guarantee ' + ', copy (char* to,int n characters, int start = 0) copies the n characters from the start position to the point where to points.

SUBSTRING: substr (int start,int N) returns a string of n characters from start, with the original object still intact

Append: Append (int n,char c) append n characters at the end

Find: Find (char c,int start=0)//from left to right

Find (const char* s, int start=0)//c style

Find (const string& s, int start=0)//c++ style

RFind (...)//parameters are searched from right to left, where you can use String::npos to represent the end npos = 1

Find_first_of (...) Parameters like find, find the first one

Find_fist_of (String S,int start=0), starting from the start position in the string s containing the characters

Find_first_of ("+-*/") indicates that the first operator found in the original string has a return position, no return NPOs found

Find_last_of (...)

Find_fist_not_of (...)

Find_last_not_of (...)

Find return subscript, not found return String::npos

Delete: erase (int start=0,int n = string::npos)

Replace with: replace (int start,int n, new String)

replace (int start,int n,int N2,char C2)

Replace n characters starting with start position with a new string or n2 a C2

Insert: Insert (int pos, new string)

Intsert (int pos,int N,char c)

C + + non-string input: Get (BUF) Easy bounds, fgets (buf,sizeof (BUF), stdin) preserves newline characters at the end, scanf ("%[^\n]", buf) read \ n, reading a row is also easy to cross the line

String Read line: string s; Getline (cin,s);

C + + Learning Note 12--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.