TAILIEUCHUNG - Absolute C++ (4th Edition) part 30

Absolute C++ (4th Edition) part 30. KEY BENEFIT: C++ programming concepts and techniques are presented in a straightforward style using understandable language and code. KEY TOPICS: C++ Basics; Flow of Control; Function Basics; Parameters and Overloading; Arrays; Structures and Classes; Constructors; Operator Overloading, Friends, and References; Strings; Pointers and Dynamic Arrays; Separate Compilation and Namespaces; Streams and File I/O; Recursion; Inheritance; Polymorphism and Virtual Functions; Templates; Linked Data Structures; Exception Handling; Standard Template Library; Patterns and UML. MARKET: Useful for both beginning and intermediate C++ programmers. . | Vectors A Preview of the Standard Template Library 293 The vector definition is given in the library vector which places it in the std namespace. Thus a file that uses vectors would include the following or something similar include vector using namespace std Vectors Vectors are used very much like arrays but a vector does not have a fixed size. If it needs more capacity to store another element its capacity is automatically increased. Vectors are defined in the library vector which places them in the std namespace. Thus a file that uses vectors would include the following lines include vector using namespace std The vector class for a given Base_Type is written vector Base_Type . Two sample vector declarations are as follows vector int v default constructor producing an empty vector. vector AClass record 20 vector constructor uses the default constructor for AClass to initialize 20 elements. Elements are added to a vector using the member function push_back as illustrated below 42 Once an element position has received its first element either with push_back or with a constructor initialization that element position can then be accessed using square bracket notation just like an array element. Pitfall Using Square Brackets beyond the Vector Size If v is a vector and i is greater than or equal to then the element v i does not yet exits and needs to be created by using push_back to add elements up to and including position i. If you try to set v i for i greater than or equal to as in v i n then you may or may not get an error message but your program will undoubtedly misbehave at some point. 294 Constructors and Other Tools Tip Vector Assignment Is Well Behaved The assignment operator with vectors does an element-by-element assignment to the vector on the left-hand side of the assignment operator increasing capacity if needed and resetting the size of the vector on the left-hand side of the assignment operator . Thus provided the assignment

TỪ KHÓA LIÊN QUAN
TÀI LIỆU MỚI ĐĂNG
TAILIEUCHUNG - Chia sẻ tài liệu không giới hạn
Địa chỉ : 444 Hoang Hoa Tham, Hanoi, Viet Nam
Website : tailieuchung.com
Email : tailieuchung20@gmail.com
Tailieuchung.com là thư viện tài liệu trực tuyến, nơi chia sẽ trao đổi hàng triệu tài liệu như luận văn đồ án, sách, giáo trình, đề thi.
Chúng tôi không chịu trách nhiệm liên quan đến các vấn đề bản quyền nội dung tài liệu được thành viên tự nguyện đăng tải lên, nếu phát hiện thấy tài liệu xấu hoặc tài liệu có bản quyền xin hãy email cho chúng tôi.
Đã phát hiện trình chặn quảng cáo AdBlock
Trang web này phụ thuộc vào doanh thu từ số lần hiển thị quảng cáo để tồn tại. Vui lòng tắt trình chặn quảng cáo của bạn hoặc tạm dừng tính năng chặn quảng cáo cho trang web này.