Forum Summary 3

Source: Internet
Author: User

1. Use the General STL algorithm remove () to delete elements from the list.

The remove () algorithm works in different ways than the List member functions. Generally, the container size is not changed. The general remove () algorithm returns an iterator pointing to the end of the new list. The range from start to the new end (excluding the new end element) contains all the elements left after removing. You can use the list member function erase to delete parts from the new end to the old end. That is, after the romove method is used, the end points to the previous end, which is not new. The remove method removes an element and copies it as the next (removes the first element, all the following elements are assigned to their previous elements. This

Behavior contradicts the main advantage of lists-the ability to insert, move, and remove

Elements by modifying the links instead of the values.) This causes serious waste.

 

2. The sscanf function is similar to scanf function. It reads data from the buffer to the variable. sprintf and prinft are similar. It sends the output from the variable to the buffer.

That is, the first parameter is output for sscanf and input for sprinf.

Example: int main (INT argc, char * argv [])

{

Long l_test;

Char test [10] = "0x0021c0 ";

 

Sscanf (test, "% x", & l_test );

Printf ("string = % s integer = % d/N", test, l_test );

 

Test [0] = '/0 ';

Sprintf (test, "0 x 00% X", l_test); // test = "0x0021c0 ";

Printf ("string = % s integer = % d/N", test, l_test );

 

System ("pause ");

Return 0;

}

 

3

Static in the base class can be inherited from the derived class, but in the entire inheritance class tree, only the base class has a static object,
A derived class can have only one static object. It can also access the static object of the base class,
The permission is the same as the public, private, and protected restrictions in the inheritance.

The static variables and functions of the parent class are still available in the derived class, but are subject to access control (for example, the private fields of the parent class are not accessible). For static variables, the static variables in the derived class and the parent class share space. Pay special attention to this when using static variables for reference counting.

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.