小编Ken*_*lah的帖子

当索引 0 为空时访问向量

vectors[0]为什么我已经pop_back()迈出了第一步仍然可以获得价值?
我猜现在我的vectors已经空了,请致电检查empty()

#include <iostream>
#include <vector>

struct Vector2 {
    int x, y;

    Vector2(int _x, int _y)
        : x(_x)
        , y(_y) {}

    Vector2(const Vector2& vec)
        : x(vec.x)
        , y(vec.y) {
        std::cout << "[Copy] Vector2{" << x << "," << y << "} copied!"
                  << std::endl;
    }

    void Print() {
        std::cout << "[Print] Vector2{" << x << "," << y << "}" << std::endl;
    }
};

void PrintVectors(const std::vector<Vector2>& vectors) {
    std::cout << "---" << std::endl; …
Run Code Online (Sandbox Code Playgroud)

c++ stl stdvector

3
推荐指数
1
解决办法
1612
查看次数

标签 统计

c++ ×1

stdvector ×1

stl ×1