小编dja*_*ooo的帖子

如何使用擦除删除成语从struct的向量中擦除值?

如何从struct的vector中删除所有值,其中struct value k等于0?

struct tabuRecord {
int x;
int y;
int k;
tabuRecord( int x, int y, int k)
    : x(x), y(y), k(k){}
};  

vector <tabuRecord> tabu;

v.insert(v.begin(), tabuRecord(1, 2, 3));
v.insert(v.begin(), tabuRecord(4, 5, 0));
v.insert(v.begin(), tabuRecord(7, 8, 9));
v.insert(v.begin(), tabuRecord(10, 11, 0));
Run Code Online (Sandbox Code Playgroud)

我试过了

tabu.erase(std::remove(tabu.begin(), tabu.end(), tabu.k=0), tabu.end());
Run Code Online (Sandbox Code Playgroud)

tabu.erase(std::remove(tabu.begin(), tabu.end(), tabuRecord.k=0), tabu.end());
Run Code Online (Sandbox Code Playgroud)

c++ struct vector erase-remove-idiom

0
推荐指数
1
解决办法
97
查看次数

标签 统计

c++ ×1

erase-remove-idiom ×1

struct ×1

vector ×1