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

Latest commit

History

History
26 lines (20 loc) 路 754 Bytes

move.md

File metadata and controls

26 lines (20 loc) 路 754 Bytes

move

Description: Moves the element to the vector permanently. The value is lost after the process.

Example:

    std::string str1 = "Hello";             
    std::string str2 = "Word";             

    std::vector<std::string> avector;

    avector.push_back (str1);               // copies the first string
    avector.push_back (std::move(str2));    // moves the second string

    std::cout << "Printing the vector: ";
    for (std::string& x:avector) {
        std::cout << ' ' << x;  
    } 
    std::cout << '\n';

    std::cout << "First string after copy: "
              << str1 << std::endl;
    std::cout << "Second string after move: "
              << str2 << std::endl;

Run Code