Valid C ++ 49,50, valid tive4950

Source: Internet
Author: User

Valid C ++ 49,50, valid tive4950

49. Familiar with the standard library.

The C ++ standard library is large.

First, there are many functions in the standard library. To avoid name conflicts, use the namespace std. The previous database functions are stored in <. h> and are now pseudo-standard libraries. Instead of directly adding all these header files to the namespace, the Standards Committee can only re-create a header file without. h. The same method is used for header files in C, but a c is added before each name, for example, <string. h> in C is changed to <cstring>. The old c ++ header file is officially opposed to use, but the old c header file is not, in order to maintain compatibility with C. For example, <string. h> it is the old C header file, which corresponds to the string processing function based on char *. <string> it contains the C ++ header file of std and corresponds to the new string class, <cstring> is the std Version of the C header file, but there is no old c ++ version of the string class, because it is not officially recommended.

Second, almost all databases are templates. For example, iostream is used to operate a streaming. The stream class is actually a class template, and the character type is specified when the stream class is instantiated. Even a string is actually a template. The type parameter limits the character type in each string class. The string type declaration is:

typedef basic_string<char, char_traits<char>, allocator<char> >string;

The character type here is the same as the character type in iostream. It is not a char but a character in a stream. Here, the character type determines its parameter, character types refer to character sets, because different character sets have different implementation details, such as special end characters and the most effective way to copy their arrays, these features are referred to as traits in the standard. Then there is a way for the string object to execute dynamic memory allocation, using a Allocator parameter, while the Allocator type object is used to allocate and release the memory of the string object, which is a memory manager. Do not manually declare any part of the standard library.

Iostream, compared with the traditional Iostream, it has been templated and its inheritance hierarchy has been modified to increase the ability to throw exceptions and support string (through stringstream) and internationalization (via locales ). The new Iostream can treat strings and files as streams, and more extensive control over streaming behaviors, including caching and initialization.

Containers, the standard library provides efficient implementation, such as vector, list, queue, stack, deque, map, set, and bitset. String is the container. Any operation on the container applies to string. The implementation of the standard library is efficient. Using containers can eliminate Memory leakage caused by dynamic memory allocation.

Algorithm. The standard library provides a large number of simple methods called algorithm, which are actually function templates, most of which are applicable to all containers in the library and built-in arrays. The algorithm uses the container content as a sequence. Each algorithm can apply a sequence or a subsequence corresponding to all values in a container. Standard algorithms include for_each, which calls a function for each element in the sequence. find finds the first position containing a value in the sequence, and count_if calculates the number of elements in the sequence that meet a certain condition, equal checks whether the values of the elements contained in the two sequences are completely equal. search finds the starting position of a sub-sequence in a sequence and copies one sequence to another, unique deletes duplicate values in the sequence, the values in the rotate sequence, and the sort sorts the values in the sequence. Like container operations, the algorithm also guarantees performance.

International support. Provides features that help develop international software. Facets and locales are the main components that support internationalization. Facets describes the characteristics of a culture, including sorting rules (that is, how the characters in certain regional character sets should be sorted), how the date and time should be represented, how Should numbers and currency values be expressed, how should information tokens be mapped to clear language information, and so on. Locales binds multiple sets of facets. facets refers to one of the features mentioned earlier, while locales indicates a rule for a country composed of multiple facets, if locales indicates how Americans solve the preceding problems.

Support for digital processing. The C ++ Library provides templates for complex classes and special arrays specially designed for numerical programming. For example, valarray objects can be used to save any elements that can be overlapped,

Diagnosis is supported. The standard library supports three error reporting methods: C's assertions, error numbers, and exception. The exception first generates logic_error and runtime_error, and then these two classes derive a specific error type. logic_error indicates a logical error in the software, which can be prevented by more careful Program Design in theory. Runtime_error is an exception of the runtime_error type.

Containers and algorithms in the standard library are generally referred to as STL in the standard template library. STL is the most innovative part of the standard library. Its architecture is scalable and can be expanded a lot according to STL specifications.


50. Improve understanding of C ++.

The primary objective of C ++ design: compatibility with C, efficiency, and compatibility with traditional development tools and environments to solve practical problems (that is, object-oriented ).

The above goals clarify a large number of implementation details in the C ++ language. For example, why do implicitly generated copy constructors and assignment operators work like this, especially the shortest copy problem caused by pointers? This is because C copies and assigns values to struct and must be compatible with C. Why does the Destructor not be automatically declared as virtual? Why must the implementation details appear in the class definition? If you do not do this, it will cause performance loss and the efficiency is very important. Why cannot C ++ detect the initialization dependency between non-local static objects? Because C ++ supports separate compilation (that is, separate compilation of the source module, and then link Multiple Target files to form executable programs), it depends on the existing linker and does not deal with program data, therefore, the c ++ compiler is almost impossible to know everything about the entire program. Why does C ++ not free programmers from complicated transactions such as memory management and low-level pointer operations? Because some programmers need these processing capabilities, the need of a real programmer is important.





Use the thread communication mechanism to print the following results with two threads: 1 2 A 3 4 B 5 6 C 7 8 D 49 50 Y 51 52 Z

Public class MyTestThread1 {public static void main (String [] args) {Object obj = new Object (); Thread1 t1 = new Thread1 (obj); t1.start (); thread2 t2 = new Thread2 (obj); Thread thread = new Thread (t2); thread. start ();}
}
Class Thread1 extends Thread {private Object obj;
Public Thread1 (Object obj) {this. obj = obj ;}
@ Override public void run () {synchronized (obj) {for (int I = 1; I <= 26; I ++) {System. out. println (2 * I-1); System. out. println (2 * I) ;}}} class Thread2 implements Runnable {private Object obj;
Public Thread2 (Object obj) {this. obj = obj ;}
Public void run () {synchronized (obj) {for (char c = 'a'; c <= 'Z'; c ++) {System. out. println (c );}}}}

 
Buddhism says dazheng 48-352a, 50,551 B, 49,796 c ~ What is 797a?

48 volume 352 page

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.