Skip to content
This repository has been archived by the owner on Nov 8, 2023. It is now read-only.

Latest commit

History

History
35 lines (26 loc) 路 771 Bytes

cbegin.md

File metadata and controls

35 lines (26 loc) 路 771 Bytes

cbegin

Description : The function returns an iterator which is used to iterate container.

Notes:

  1. The iterator points to the beginning of the vector.
  2. Iterator cannot modify the contents of the vector.

Example:

// Demonstrates cbegin() 
#include <iostream>
#include <vector>

int main(){
    //declares an empty vector
    std::vector<int> vec;
    
    //inserting elements in vector
    vec.push_back(101);
    vec.push_back(12);
    vec.push_back(999);
  
    //Displaying elements of  vector
    std::cout << "Content of the vector \n";
    for (auto it = vec.cbegin(); it != vec.end(); ++it){ 
        std::cout << *it << '\n'; 
    }
    return 0;
}

Run Code