Skip to Content

Learn C++ Programming in 1hr + Code

Learn C++ Programming in 1hr + Code

Best Ever C++ Tutoriali for C Programmer

Code Snip: Part1 | Part2 | Part3

Data Types | Arithmetic | If Statement | Switch Statement | Ternary Operator | Arrays | For Loop | While Loop | Do While Loop | User Input | Convert String | Strings | Vectors | Functions | Recursive Function | File I/O | Exception Handling | Pointers | Reference Operator | Classes / Objects | Private | Static Variables | Public / Encapsulation | Constructors | Static Functions | this | Inheritance | Call Superclass Constructor | Execute Static Method | Virtual Methods | Polymorphism | Abstract Data Type

#include <string>

More details Here

Operations on strings

  1. getline() :- This function is used to store a stream of characters as entered by the user in the object memory.
  2. push_back() :- This function is used to input a character at the end of the string.
  3. pop_back() :- Introduced from C++11(for strings), this function is used to delete the last character from the string.

Capacity Functions

  1. length():-This function finds the length of the string
  2. resize() :- This function changes the size of string, the size can be increased or decreased.
  3. capacity() :- This function returns the capacity allocated to the string, which can be equal to or more than the size of the string. Additional space is allocated so that when the new characters are added to the string, the operations can be done efficiently.
  4. shrink_to_fit() :- This function decreases the capacity of the string and makes it equal to the minimum capacity of the string. This operation is useful to save additional memory if we are sure that no further addition of characters have to be made.

Iterator Functions

  1. begin() :- This function returns an iterator to beginning of the string.
  2. end() :- This function returns an iterator to end of the string.
  3. rbegin() :- This function returns a reverse iterator pointing at the end of string.
  4. rend() :- This function returns a reverse iterator pointing at beginning of string.

Manipulating Functions

  1. copy(“char array”, len, pos) :- This function copies the substring in target character array mentioned in its arguments. It takes 3 arguments, target char array, length to be copied and starting position in string to start copying.
#include <vector>

More details Here

Iterators Functions

  1. begin() – Returns an iterator pointing to the first element in the vector
  2. end() – Returns an iterator pointing to the theoretical element that follows the last element in the vector
  3. rbegin() – Returns a reverse iterator pointing to the last element in the vector (reverse beginning). It moves from last to first element
  4. rend() – Returns a reverse iterator pointing to the theoretical element preceding the first element in the vector (considered as reverse end)

Capacity Functions

  1. empty() – Returns whether the container is empty.
  2. size() – Returns the number of elements in the vector.
  3. capacity() – Returns the size of the storage space currently allocated to the vector expressed as number of elements.
  4. resize(n) – Resizes the container so that it contains ‘n’ elements.
  5. shrink_to_fit() – Reduces the capacity of the container to fit its size and destroys all elements beyond the capacity.

Element Access

  1. reference operator [g] – Returns a reference to the element at position ‘g’ in the vector
  2. at(g) – Returns a reference to the element at position ‘g’ in the vector
  3. front() – Returns a reference to the first element in the vector
  4. back() – Returns a reference to the last element in the vector

Modifiers Functions

  1. insert() – It inserts new elements before the element at the specified position
  2. push_back() – It push the elements into a vector from the back
  3. pop_back() – It is used to pop or remove elements from a vector from the back.
  4. erase() – It is used to remove elements from a container from the specified position or range.
  5. clear() – It is used to remove all the elements of the vector container
  6. emplace() – It extends the container by inserting new element at position
  7. emplace_back() – It is used to insert a new element into the vector container, the new element is added to the end of the vector.

Last updated:
Categories: blogs
Tags: c++

LEAVE A REPLY