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

Latest commit

History

History
33 lines (25 loc) 路 821 Bytes

clear.md

File metadata and controls

33 lines (25 loc) 路 821 Bytes

clear

Description: Remove all current elements of the vector, reducing its size to 0.

Example:

    std::vector<int> myVector;
    
    // Initialize vector with the values {1,2,3,4,5}
    myVector = {1,2,3,4,5};
    
    // Output: "1 2 3 4 5"
    for (int i : myVector) {
        std::cout << i << " ";
    }
    std::cout << std::endl;
    
    // Size of vector is 5
    std::cout << "Vector size: " << myVector.size() << std::endl;
    
    // Clear the vector of all values, myVector now contains no values
    myVector.clear(); 
    
    // Output is blank
    for (int i : myVector) {
        std::cout << i << " ";
    }
    std::cout << std::endl;

    // Size of vector is 0
    std::cout << "Vector size: " << myVector.size() << std::endl;

Run Code