STL Video _01

Source: Internet
Author: User
Tags locale

ZC: Here in the video there is a debugging tips, vs08/vs2010 start, the console program will automatically exit (unlike VC6), then you can set a breakpoint on the last sentence of the function exit, and then view the information printed by the console.
ZC: This tells me that the good thing about using string is that the index is out of bounds when the string is manipulated (such as copy/delete operations)

"01:05", the main points of this lecture are as follows:
One, what things STL, the advantage of using STL;
Second, the use of the STL string type method.

Introduction to "01:25" STL
Standard Template Library
"01:45" STL code, broadly speaking, is divided into 3 categories: containers, iterators, algorithms. Containers and algorithms can be seamlessly connected through iterators.
"02:02" string and wstring are also part of the STL

"02:28" the composition and internal relationship of STL
"03:05" Benefits of STL
"03:12" A summary of what is called a container
"04:35" an important feature of STL
The separation of data structures (containers) and algorithms ==> a high rate of reuse. I have this sort of algorithm that can be used either for the list container or for other containers.
"05:55" such as STL has a sort (...) Sorting functions that we can use to manipulate containers such as vectors and lists
"06:15" STL has high reusability, high performance and cross-platform advantages.

"06:27" Benefits of using STL
01_02_ the benefits of using STL. jpg
(1), "06:28" high reusability
(2), "07:50" high performance
01_03_ the benefits of using STL. jpg
(3), "08:24" high portability
(4), "08:52" cross-platform

"09:20" Other benefits of STL: Programmers do not have to think about the implementation process of STL, as long as they can master the STL skillfully. You can focus on your business logic.


"10:40" string
What string is, how string and char* are compared, how to invoke the STL string, the constructor of the string, how to take the character (string), how to get the const char * (the operation inside), and how to copy the space that the char* points to.
We'll talk about how the string takes its length, how many characters it contains, how the string is assigned, how string two strings are concatenated, how to compare, how to fetch substrings inside string strings, how to find, how to insert, how to delete, how to replace, and wstring, the conversion of string and wstring, the unification of string encoding.

What is the "12:11" string
What is 01_04_string. jpg
"12:30" The difference between a string and a char*:
First, string is a class, char* is a pointing character (ZC: string?) Pointer, string encapsulates the char*, manages the string, and is a container of type char*.
The "12:45" string does not consider memory release and cross-border issues. The string manages the memory allocated by the char*, and each time the string is copied, the value is maintained by the string class, regardless of the problem of copying out of bounds and crossing the value.
The "13:05" string supports the operation. For example, two string connections.
The "13:22" string also provides a series of string manipulation functions. such as Find, copy, delete, replace, insert and so on.
"13:31" how we use String. Before using it, first in the file of our code (inside the/cpp file inside the header file), first write a line of code:

#include <string>
using namespace Std;

The benefit of this writing is to prevent this string from having the same name as the string defined in the rest of the program (of course we'd better be careful not to duplicate the same name).
"14:15" "using namespace std;" is a form of STL relative standard that is intended to define a namespace.


Constructor for "14:28" string
The 01_05_string constructor. jpg
The "14:32" constructor typically has a default constructor, a copy constructor, and a constructor with parameters.

"17:22" takes a character from a string (string)
Two types: [?] and at (?)
"18:43" 01_06_string the character operation. jpg
The only difference between "19:25" [?] and at (?): These two methods are not the same for cross-border processing
"19:45" For example, we take the 50th character (there is no 50 characters): "20:03" with "[?]" To fetch, the program will read the address is wrong, will cross the border. STL does not make a cross-border judgment on [?], ∴ it directly leads to the crash of the program. "20:20" to "at (?)" , it does not produce a crash problem, it throws an exception, out of range of the exception (Out_of_range), the exception can be "Try{}catch (...) {} "caught, this time catch (???) It is possible to write a specific type of error capture.

"21:32" We see the pick character

const char &operator[] (int n) const;
const char &at (int n) const;
Char &operator[] (int n);
char &at (int n);

What is the difference between the above "const char &" and the Direct "Char &"?
"21:40" When we want to get a character, we actually call the corresponding two functions that return "const char &".
"21:55" If we want to change the value of a character in a position, ZC: the corresponding two functions that return "char &" are called. "22:30" "22:35" why not const? ∵ indicates that the value inside can be modified.


"22:50" string how to get the "const char*" inside the operation.
We sometimes want to print out the contents of our string and print it to the screen.
"23:22" is generally used "cout <<??" <<endl;, but it does not accept string, accept char*.
"24:00" String::c_str () returns "Const char*"


"25:15" How to copy the contents of string strings into the memory space pointed by char*
"25:32" copies the string to the char* point of the memory space operation
01_07_ the operation of copying a string to the memory space pointed to by Pchar. jpg
int copy (char *s, int n, int pos=0) const;
ZC: Note the number of parameters in front, starting position in the rear
ZC: note is string::copy (...), do not and Delphi inside the copy function to confuse ...

"29:30" How to get the length of a string, how to tell if the string is empty
Of course, the string length is ==0, which is definitely empty. String length ==0, may sometimes not very convenient, with BOOL String::empty () const;
"29:50" The length of the 01_08_string. jpg

Assignment of "30:13" 01_09_string. jpg
"30:28" 1, =:const string& ==> string&
"31:23" 2, String &string::assign (const char *s); All characters of S
"31:31" 3, String &string::assign (const char *s, int n); The first n characters of S

Assignment of "31:52" 01_10_string. jpg
"31:55" 4, String &string::assign (const string &s);//similar to operator=
"32:08" 5, string &string::assign (int n, char c); Similar to the corresponding function inside the constructor. n the same character C ==> string&
"32:30" 6, String &string::assign (const string &s, int start, int n);


"32:36" character-swapping connection
"34:28" 01_11_string connection. jpg
"33:01" 1, + =
Example of "33:19" before preparation
(1), + = Const string &
(2), + = const char *
"35:15" 2, string::append (...)
(1), const char *
(2), const char *, int n
"37:03" 01_12_string connection. jpg
(3), const string &//with + =
(4), const string &s, int pos, int n
(5), int n, char c


Comparison of "40:30" string strings
Comparison of 01_13_string. jpg

int String::compare (const string &s) const;
int string::compare (const char *s) const;
More than and returns 1
Less than--returns-1
Equals--Returns 0
ASCII Code table dictionary order, smaller before the row

Example of "41:49" comparison
"42:31" character is a one to compare, once the outcome, the more long ended, the direct return value


"44:02" How to obtain a substring of string
"44:15" substring of 01_14_string. jpg
String string::substr (int pos=0, int n=npos) const; Returns a substring of n characters starting at the POS
ZC: The default value of the following parameter means that it should be all the characters from the Pos backwards? Test it down, that's exactly the case.


Lookup of "15:20" string
"45:56" has two directions to find
"46:30" For example, looking for file extension, from backward to better ==> string::rfind (...)
Look for "46:55" 01_15_string. jpg
Example of "47:18" string lookup
(1), find characters
(2), find const char* string
"49:05" ZC: Here's the example, both I and the video author think should return 3 (the beginning of the string to find), but the return is 5 (the end of the string to find)
"50:18" ZC: Find out why, really should be 3, incredibly is ∵ string in single quotes, but incredibly can compile the past ... Tested, really compiled in the past, why?
(3), find const string& string
(4), String::find (...) is not found, then returns-1

"51:45" Reverse Access (01_16_string lookup (reverse). jpg)
ZC: Test to see the meaning of the second parameter (is it a positive index or an inverted index?). ), the meaning of the return value (is it a positive index or an inverted index?). )


Insertion of "52:50" string
"53:33" String::insert (...)
Insert. jpg for "54:25" 01_17_string

Delete of "55:02" string
String::erase (the index of the character to begin deleting, and how many characters to delete)
Delete in our other containers are used erase (...), such as a vector inside the deletion of a node, map inside Delete what
Example of "55:50" deletion


Substitution of "56:29" string
String::replace (...)
"57:05" has two operations:
(1), first the index value and the number of characters determined (string) to delete
(2), then insert new character (string)
"57:23" Example
"58:15" the first replace () and the second replace () they function the same, "58:22" The third (there is another), is the Exchange
"58:33" interchange example--String::swap (...)

"59:50" The difference between a string and a wstring

Conversion of "01:00:30" string and wstring
Conversion of 01_18_string to wstring. jpg
(1), Windows API
(2), ATL ==> COM ==> This can only be used for the win platform ...
"01:01:01" zc:t2w, w2t these two ppt inside not, is the video author oral Speaking
"01:01:08" the conversion of 01_19_string to wstring. jpg
(3), cross-platform CRT library mbstowcs ()/wcstombs (), need to set locale
ZC: What does "set locale" mean? Do you mean "#include <locale.h>"? It seems that functions such as setlocale () need to be called.
"01:01:43" the conversion of 01_20_string to wstring. jpg
"01:02:01" the conversion of 01_21_string to wstring. jpg


"01:02:45" using the same scheme as string/wstring
"01:02:55" 01_22_ encoding unification, writing a single source code. jpg


"01:03:30" This talk about the following points:
"01:03:32" 1, what is the benefits of Stl,stl, broadly divided into three categories ....
ZC: See PPT Bar ...

///////

///////

///////

///////

///////

///////

///////

///////

///////

///////

///////

///////

///////

///////

///////

///////

///////

///////

///////

///////

///////

C

STL Video _01

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.