📜  cpp std 列表示例 - C++ 代码示例

📅  最后修改于: 2022-03-11 14:44:56.119000             🧑  作者: Mango

代码示例1
#include 
#include 
#include 
 
int main()
{
    // Create a list containing integers
    std::list l = { 7, 5, 16, 8 };
 
    // Add an integer to the front of the list
    l.push_front(25);
    // Add an integer to the back of the list
    l.push_back(13);
 
    // Insert an integer before 16 by searching
    auto it = std::find(l.begin(), l.end(), 16);
    if (it != l.end()) {
        l.insert(it, 42);
    }
 
    // Print out the list
    std::cout << "l = { ";
    for (int n : l) {
        std::cout << n << ", ";
    }
    std::cout << "};\n";
}