由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
Programming版 - Remove elements from multiple vectors in C++
相关主题
Switch from Matlab to C(C++)?问一个C++的问题
C++ vector 一边遍历一边删C++ read matrix from txt file
[请教]iterator and reference in C++ vector还请教一个关于C++的问题
问一个OOP的C++问题一个C++的概念问题
请教:distance calculation问个C++ 中拷贝vector的问题
请教一个优化问题一道C++ STL面试题 (转载)
STL/vector引用成员变量。请教: 用stable_sort 在VC++下通过但在g++下通不过
能帮我看看Ruby的这道题吗?C++里面怎么存储长度不同的array?
相关话题的讨论汇总
话题: remove话题: c++话题: elements话题: vectors话题: person
进入Programming版参与讨论
1 (共1页)
d**t
发帖数: 183
1
vector name;
vector age;
How do I remove all the persons old than 30 from both name and age? I can do
it in a loop, but I am wondering if there is a more elegant way.
Thanks,
t****t
发帖数: 6806
2
struct Person { string name; int age; };
vector person;

do

【在 d**t 的大作中提到】
: vector name;
: vector age;
: How do I remove all the persons old than 30 from both name and age? I can do
: it in a loop, but I am wondering if there is a more elegant way.
: Thanks,

d**t
发帖数: 183
3
Very nice. I will try it. Thanks.
Just curious. Is this the only way without using a loop?

【在 t****t 的大作中提到】
: struct Person { string name; int age; };
: vector person;
:
: do

i*****f
发帖数: 578
4
you still need to use a loop this way

【在 d**t 的大作中提到】
: Very nice. I will try it. Thanks.
: Just curious. Is this the only way without using a loop?

d**t
发帖数: 183
5
I am thinking about using remove_if from the stl. Am I wrong?

【在 i*****f 的大作中提到】
: you still need to use a loop this way
t****t
发帖数: 6806
6
yes, you can use remove_if. but let me remind you that remove_if only "
compress" the range. you still have to remove the extra elements with erase(
) by yourself.
person.erase(remove_if(person.begin(), person.end(), your_predicate), person
.end());

【在 d**t 的大作中提到】
: I am thinking about using remove_if from the stl. Am I wrong?
d**t
发帖数: 183
7
Many thanks.

erase(
person

【在 t****t 的大作中提到】
: yes, you can use remove_if. but let me remind you that remove_if only "
: compress" the range. you still have to remove the extra elements with erase(
: ) by yourself.
: person.erase(remove_if(person.begin(), person.end(), your_predicate), person
: .end());

r*********r
发帖数: 3195
8
用 pair 更好一点.
1 (共1页)
进入Programming版参与讨论
相关主题
C++里面怎么存储长度不同的array?请教:distance calculation
C++debug遇到的问题请教一个优化问题
请问C++如何初始化类时就传入一个数组参数STL/vector引用成员变量。
C++ vector能帮我看看Ruby的这道题吗?
Switch from Matlab to C(C++)?问一个C++的问题
C++ vector 一边遍历一边删C++ read matrix from txt file
[请教]iterator and reference in C++ vector还请教一个关于C++的问题
问一个OOP的C++问题一个C++的概念问题
相关话题的讨论汇总
话题: remove话题: c++话题: elements话题: vectors话题: person