C++ Library –

C++ Library – <regex> ”; Previous Next Introduction It is a standardized way to express patterns to be matched against sequences of characters. some of typical regex parameters are as shown below − Target sequence (subject) − It is used to searched for the sequence pattern. Regular expression (pattern) − It is used to searched for in the target sequence. Matches array − Matches information is stored in one of the special match_results array types (such as cmatch or smatch). Replacement strin − This operation replaces the matches. Regex operations Sr.No. Regex operation & description 1 regex_match It is a match sequence. 2 regex_search It is a search sequence. 3 regex_replace It is a replace matched sequence. Iterator types Sr.No. Iterator type & description 1 regex_iterator It is a regex iterator. 2 regex_token_iterator It is a regex token iterator. basic_regex instantiations Sr.No. Instantiation & description 1 regex It is a regex class. 2 wregex It is a wregex class. match_results instantiations Sr.No. match_results instantiation & description 1 cmatch These are match_results for string literals. 2 wcmatch These are match_results for wide string literals. 3 smatch These are match_results for string objects. 4 wsmatch These are match_results for wide string objects. sub_match instantiations Sr.No. sub_match instantiation & description 1 csub_match It is a sub_match for string literals. 2 wcsub_match It is a sub_match for wide string literals. 3 ssub_match It is a sub_match for strings. 4 wssub_match It is a sub_match for wide strings. Namespaces Sr.No. Namespace & description 1 regex_constants It is a regex constants. Print Page Previous Next Advertisements ”;

C++ Library –

C++ Library – <set> ”; Previous Next Introduction A set is an Associative container which contains a sorted set of unique objects of type Key. Each element may occur only once, so duplicates are not allowed. There are four kind of Associative containers: set, multiset, map and multimap. The value of the elements in a set cannot be modified once in the container, i.e., the elements are always const. But they can be inserted or removed from the container. set containers are generally slower than unordered_set containers in accessing individual elements by their key, but they allow the direct iteration on subsets based on their order. Definition Below is definition of std::set from <set> header file template < class Key, class Compare = std::less<Key>, class Allocator = std::allocator<Key> > class set; Parameters Key − Type of the element contained. Key may be substituted by any other data type including user-defined type. Member types Following member types can be used as parameters or return type by member functions. Sr.No. Member types Definition 1 key_type Key 2 value_type Key 3 reference Allocator::reference value_type& 4 const_reference Allocator::const_reference const value_type& 5 pointer Allocator::pointer std::allocator_traits<Allocator>::pointer 6 const_pointer Allocator::const_pointer std::allocator_traits<Allocator>::const_pointer 7 iterator BidirectionalIterator 8 const_iterator constant BidirectionalIterator 9 reverse_iterator std::reverse_iterator <iterator> 10 const_reverse_iterator std::reverse_iterator <const_iterator> 11 size_type Unsigned Integer Type (std::size_t) 12 difference_type Signed Integer Type (std::ptrdiff_t) 13 key_compare Compare 14 value_compare Compare 15 allocator_type Allocator Functions from <set> Below is list of all methods from <set> header. MEMBER FUNCTIONS DEFAULT MEMBER FUNCTIONS Sr.No. Method & Description 1 Default constructor Constructs the set container. 2 Range constructor Constructs the set container with contents of the range. 3 Copy constructor Constructs the set container with the copy of other set. 4 Move constructor Constructs the set container with the contents of other set using move semantics. 5 Initializer-list constructor Constructs the set container with contents of the inializer list. 6 (destructor) Destructs the set container. 7 operator= Assigns values to the set container. ITERATORS Sr.No. Method & Description 1 set::begin Returns the iterator to beginning. 2 set::cbegin Returns the const iterator to beginning. 3 set::end Returns the iterator to end. 4 set::cend Returns the const iterator to end. 5 set::rbegin Returns the reverse iterator to reverse beginning. 6 set::crbegin Return const reverse iterator to reverse beginning. 7 set::rend Returns the reverse iterator to reverse end. 8 set::crend Returns the const reverse iterator to reverse end. CAPACITY Sr.No. Method & Description 1 set::empty Returns wheteher the set container is empty. 2 set::size Returns the number of elements in the set container. 3 set::max_size Returns the maximum number of elements that the set container can hold. MODIFIERS Sr.No. Method & Description 1 set::clear Removes all elements from the set container. 2 set::insert Inserts new element in the set container. 3 set::emplace Inserts new element in the set, if its unique. 4 set::emplace_hint Inserts new element in the set, if its unique, with a hint on the inserting position. 5 set::erase Removes either a single element or a range of elements from the set container. 6 set::swap Exchanges the content of the container by the content of another set container of the same type. LOOKUP Sr.No. Method & Description 1 set::count Returns the number of elements with matching value in the set container. 2 set::find Searches the set container for value and returns an iterator to it if found, else returns an iterator to set::end. 3 set::lower_bound Returns an iterator pointing to the first element in the set container which is not considered to go before value. 4 set::upper_bound Returns an iterator pointing to the first element in the set container which is considered to go after value. 5 set::equal_range Returns the bounds of a range that includes all the elements in the set container that are equivalent to value. OBSERVERS Sr.No. Method & Description 1 set::key_comp Returns a copy of the comparison object used by the set container. 2 set::value_comp Returns a copy of the comparison object used by the set container. ALLOCATOR Sr.No. Method & Description 1 set::get_allocator Returns a copy of the allocator object associated with the set container. Print Page Previous Next Advertisements ”;

C++ STL – Cheat Sheet

C++ STL – Cheat Sheet ”; Previous Next This C++ STL cheatsheet covers a wide range of topics from basic STL like vectors, hashmaps, sets, etc., to advanced concepts like functors, iterators, and so on. It is designed for programmers who want to quickly read through key concepts along with the syntax and related examples. Introduction The Standard Template Library (STL) is a C++ library that contains all class and function templates. It is used for implementing the basic Data Structures (like Hashset, Heap, List, etc.) and functions (like math, algorithms, etc.), and contains all containers available in C++ programming language. Components of STL Standard Template Library contains of several containers and functions, and can be categorized in the following manner − Containers Functors Algorithms Iterators STL Containers The STL container template class contains data structures like Dynamic Arrays (or Vectors, Lists), Hashmaps, Hashsets, Trees, Linked Lists, etc. These are used for storing and performing operations on the data. The container template has the following components − Sequential Containers Container Adapters Associative Containers Unordered Containers Each container has its respective header file, which can be included at the start of the program. For example, the std::vector is included in the #include<vector> library. Sequential Containers The sequential containers implement the data structures with sequential access. These include − Vector List Deque Array Forward List Container Adapters The container adapters implement data structures like queues, stacks, etc by providing different interfaces for sequential containers. These include − Stack Queue Priority Queue Associative Containers The associative containers are used to store ordered data that can be quickly searched using their key value. These include − Set Multiset Map Multimap Unordered Containers The unordered containers are similar to associative containers but the only difference is that they don’t store sorted data. Still, these containers provide quick search time using key-value pairs. They are − Unordered Set Unordered Multiset Unordered Map Unordered Multimap Now that we have established a learning graph of all containers, we will briefly explain each container in the STL with an exemplar code − Vector in STL The vector is initialized as a dynamic array at runtime, and its size is variable. It can be found in the C++ <vector> header file. Syntax vector<data_type> vec1; //1D vector vector<vector<data_type>> vec2; //2D vector vector<container_type<data_type>> vec3; //2D vector of other container vector<data_type> vec1(n); //vector of size n vector<data_type> vec1(n,k); // vector of size n, with each element=k There are different functions in the vector template. These are explained briefly in the table below − S.No. Function Function Explanation TC 1. begin() Returns an iterator to the first element. O(1) 2. end() Returns an iterator to the theoretical element after the last element. O(1) 3. size() Returns the number of elements present. O(1) 4. empty() Returns true if the vector is empty, false otherwise. O(1) 5. at() Return the element at a particular position. O(1) 6. assign() Assign a new value to the vector elements. O(n) 7. push_back() Adds an element to the back of the vector. O(1) 8. pop_back() Removes an element from the end. O(1) 9. insert() Insert an element at the specified position. O(n) 10. erase() Delete the elements at a specified position or range. O(n) 11. clear() Removes all elements. O(n) Here, TC indicates time complexity of different member functions of the vector template. For more information on time complexity, visit this article − Time complexity. Example // C++ program to illustrate the vector container #include <iostream> #include <vector> using namespace std; int main(){ int n=2; vector<int> vec1 = { 1, 2, 3, 4, 5 }; vector<int> vec2(n,0); vector<vector<int>> vec3(n,vector<int>(2*n,1)); vec1.push_back(6); cout << “vec1: “; for (int i = 0; i < vec1.size(); i++) { cout << vec1[i] << ” “; } cout << endl<<“vec2: “; for (int i = 0; i < vec2.size(); i++) { cout << vec2[i] << ” “; } cout << endl; vec1.erase(vec1.begin() + 4); cout << “vec1 after erasing: “; for (auto i = vec1.begin(); i != vec1.end(); i++) { cout << *i << ” “; } cout << endl; cout << “vec3:-” << endl; for (auto i : vec3) { for (auto j : i) { cout << j << ” “; } cout << endl; } cout << endl; vector<pair<int,int>> vec4; vec4.push_back({2,3}); vec4.push_back({4,3}); cout<<“vector of pairs, vec4 : “<<endl; for(auto i: vec4){ cout<<i.first<<” “<<i.second<<endl; } return 0; } Output vec1: 1 2 3 4 5 6 vec2: 0 0 vec1 after erasing: 1 2 3 4 6 vec3:- 1 1 1 1 1 1 1 1 vector of pairs, vec4 : 2 3 4 3 List in STL The list container is initialized as a doubly linked list, whereas for implementing a singly linked list, we use a forward_list. It can be found in the C++ <list> header file. Syntax list<data_type> list1; There are different functions in the list template. These are explained briefly in the table below − S.No. Function Function Explanation TC

C++ Useful Resources

C++ – Useful Resources ”; Previous Next The following resources contain additional information on C++. Please use them to get more in-depth knowledge on this topic. Useful Video Courses C Language Online Training Best Seller 69 Lectures 6 hours Tutorialspoint More Detail C++ Development Complete Course 78 Lectures 5.5 hours Frahaan Hussain More Detail C # in Telugu 38 Lectures 6.5 hours Vijay Kumar Parvatha Reddy More Detail C# in Depth: A Comprehensive Course (Beginner-To-Advanced) 108 Lectures 8 hours TELCOMA Global More Detail C# Coding Basics Course – For Beginners 86 Lectures 6.5 hours Metla Sudha Sekhar More Detail Learn C++ Programming From Scratch in Tamil 56 Lectures 13 hours Programming Line More Detail Print Page Previous Next Advertisements ”;

C++ Library –

C++ Library – <iostream> ”; Previous Next Description It is used in standard Input / Output Streams Library. Declaration Following is the declaration for iosstream function. C++98 Including this header may automatically include other headers, such as <ios>, <streambuf>, <istream>, <ostream> and/or <iosfwd>. C++11 Including <iostream> automatically includes also <ios>, <streambuf>, <istream>, <ostream> and <iosfwd>. Objects The objects of iosstream should be like this − Narrow characters (char) Sr.No. Characters Definition 1 cin Standard input stream 2 cout Standard output stream 3 cerr Standard output stream for errors 4 clog Standard output stream for logging Wide characters (wchar_t) Sr.No. Characters Definition 1 wcin Standard input stream (wide) 2 wcout SStandard output stream (wide) 3 wcerr Standard output stream for errors (wide-oriented) 4 wclog Standard output stream for logging (wide) Print Page Previous Next Advertisements ”;

C++ Library – Home

The C++ Standard Library Tutorial Resources Job Search Discussion C++ is a middle-level programming language developed by Bjarne Stroustrup starting in 1979 at Bell Labs. C++ runs on a variety of platforms, such as Windows, Mac OS, and the various versions of UNIX. The C++ Standard Library is a collection of classes, functions, macros, constants etc which have been written in the core C++ language. There is a big list of required header files which can vary depending on different compiler implementations. This header list includes the headers containing the content from the C Standard Library, a list of new C++ specific headers, and other important headers for the C++ Standard Template Library (STL). Audience The C++ Standard Library is a reference for C++ programmer to help them at every steps of their projects related to system programming. All the C++ functions have been explained in easy to understand way and they can be used easily in your C++ projects. Prerequisites A basic understanding of the C++ Programming languages will help you in understanding the C++ classes and built-in functions covered in this library. Print Page Previous Next Advertisements ”;

C++ Library –

C++ Library – <fstream> ”; Previous Next Introduction This data type represents the file stream generally, and has the capabilities of both ofstream and ifstream which means it can create files, write information to files, and read information from files. Definition Below is definition of std::fstream. template< class CharT, class Traits = std::char_traits<CharT>> class basic_fstream : public std::basic_iostream<CharT, Traits> Parameters charT − Aliased as member char_type. traits − Aliased as member traits_type. Member types Following member types can be used as parameters or return type by member functions. Sr.No. Member types Definition 1 char Character Type 2 char_traits<char> traits_type 3 int const value_type 4 int int_type 5 streampos pos_type 6 streamoff off_type Functions from <fstream> Below is list of all methods from <fstream> Member functions Sr.No. Method & description 1 fstream::close Closes the file currently associated with the object, disassociating it from the stream. 2 fstream::is_open Returns whether the stream is currently associated to a file. 3 fstream::open Opens the file identified by argument filename, associating it with the stream object. 4 fstream::operator= Returns a constant iterator which points to the start of the array. 5 fstream::rdbuf Returns a pointer to the internal filebuf object. 6 fstream::swap Exchanges all internal data between x and *this. Non-member overloaded functions Sr.No. Method & description 1 swap-free Exchanges the values of the fstream objects x and y. Print Page Previous Next Advertisements ”;

C++ Library –

C++ Library – <new> ”; Previous Next Introduction It is a header describes functions used to manage dynamic storage in C++.The header also defines some specific types and the set_new_handler / get_new_handler pair of functions as shown below − Functions Sr.No. Function & description 1 operator new It allocates storage space. 2 operator new[] It allocates storage space for array. 3 operator delete It deallocates storage space. 4 operator delete[] It deallocates storage space of array. 5 get_new_handler It is used to get new handler function. Types Sr.No. Type & description 1 nothrow_t It is a nathrow type. 2 new_handler It is a type of new handler function. 3 bad_alloc It is an exception and throws on failure allocating memory. 4 bad_array_new_length It is a bad array length exception. Constants Sr.No. Constant & description 1 nothrow It is a nathrow constants. Print Page Previous Next Advertisements ”;

C++ Library –

C++ Library – <functional> ”; Previous Next Introduction Function objects are objects specifically designed to be used with a syntax similar to that of functions. Instances of std::function can store, copy, and invoke any Callable target — functions, lambda expressions, bind expressions, or other function objects, as well as pointers to member functions and pointers to data members. Declaration Following is the declaration for std::function. template<class > class function; C++11 template< class R, class… Args > class function<R(Args…)> Parameters R − result_type. argument_type − T if sizeof…(Args)==1 and T is the first and only type in Args. Example In below example for std::function. Live Demo #include <functional> #include <iostream> struct Foo { Foo(int num) : num_(num) {} void print_add(int i) const { std::cout << num_+i << ”n”; } int num_; }; void print_num(int i) { std::cout << i << ”n”; } struct PrintNum { void operator()(int i) const { std::cout << i << ”n”; } }; int main() { std::function<void(int)> f_display = print_num; f_display(-9); std::function<void()> f_display_42 = []() { print_num(42); }; f_display_42(); std::function<void()> f_display_31337 = std::bind(print_num, 31337); f_display_31337(); std::function<void(const Foo&, int)> f_add_display = &Foo::print_add; const Foo foo(314159); f_add_display(foo, 1); std::function<int(Foo const&)> f_num = &Foo::num_; std::cout << “num_: ” << f_num(foo) << ”n”; using std::placeholders::_1; std::function<void(int)> f_add_display2= std::bind( &Foo::print_add, foo, _1 ); f_add_display2(2); std::function<void(int)> f_add_display3= std::bind( &Foo::print_add, &foo, _1 ); f_add_display3(3); std::function<void(int)> f_display_obj = PrintNum(); f_display_obj(18); } The sample output should be like this − -9 42 31337 314160 num_: 314159 314161 314162 18 Member functions Sr.No. Member functions Definition 1 (constructor) It is used to construct a new std::function instance 2 (destructor) It is used to destroy a std::function instance 3 operator= It is used to assign a new target 4 swap It is used to swap the contents 5 assign It is used to assign a new target 6 operator bool It is used to check if a valid target is contained 7 operator() It is used to invoke the target Non-member functions Sr.No. Non-member functions Definition 1 std::swap It specializes the std::swap algorithm 2 operator== operator!= It compares an std::function with nullptr Operator classes Sr.No. Operator classes Definition 1 bit_and It is a bitwise AND function object class 2 bit_or It is a bitwise OR function object class 3 bit_xor It is a bitwise XOR function object class 3 divides It is a division function object class 4 equal_to It is a function object class for equality comparison 5 greater It is a function object class for greater-than inequality comparison 6 greater_equal It is a function object class for greater-than-or-equal-to comparison 7 less It is a function object class for less-than inequality comparison 8 less_equal It is a function object class for less-than-or-equal-to comparison 9 logical_and It is a logical AND function object class 10 logical_not It is a logical NOT function object class 11 logical_or It is a logical OR function object class 12 minus It is a subtraction function object class 13 modulus It is a modulus function object class 14 multiplies It is a multiplication function object class 15 negate It is a negative function object class 16 not_equal_to It is a function object class for non-equality comparison 17 plus It is an addition function object class Print Page Previous Next Advertisements ”;

C++ Library –

C++ Library – <ios> ”; Previous Next Introduction The C++ standard libraries provide an extensive set of input/output capabilities which we will see in subsequent chapters. This chapter will discuss very basic and most common I/O operations required for C++ programming. Input-Output base classes and types for the IOStream hierarchy of classes as shown below − Types Class templates Sr.No. Member types Definition 1 basic_ios Base class for streams (type-dependent components 2 fpos Stream position class template Classes Sr.No. Member types Definition 1 ios Base class for streams (type-dependent components) 2 ios_base Base class for streams 3 wios Base class for wide character streams Other types Sr.No. Member types Definition 1 io_errc Input/output error conditions 2 streamoff Stream offset type 3 streampos Stream position type 4 streamsize Stream size type 5 wstreampos Wide stream position type Format flag manipulators (functions) Independent flags (switch on) − Sr.No. Member types Definition 1 boolalpha Alphanumerical bool values 2 showbase Show numerical base prefixes 3 showpoint Show decimal point 4 showpos Show positive signs 5 skipws Skip whitespaces 6 unitbuf Flush buffer after insertions 7 uppercase Generate upper-case letters Independent flags (switch off) − Sr.No. Member types Definition 1 noboolalpha No alphanumerical bool values 2 noshowbase Do not show numerical base prefixes 3 noshowpoint Do not show decimal point 4 noshowpos Do not show positive signs 5 noskipws Do not skip whitespaces 6 nounitbuf Do not force flushes after insertions 7 nouppercase Do not generate upper case letters Numerical base format flags (“basefield” flags) − Sr.No. Member types Definition 1 dec Use decimal base 2 hex Use hexadecimal base 3 oct Use octal base Floating-point format flags (“floatfield” flags) − Sr.No. Member types Definition 1 fixed Use fixed floating-point notation 2 scientific Use scientific floating-point notation Adustment format flags (“adjustfield” flags) − Sr.No. Member types Definition 1 internal Adjust field by inserting characters at an internal position 2 left Adjust output to the left 3 right Adjust output to the right Print Page Previous Next Advertisements ”;