【C++】STL(Standard Template Library)相談室 8
at TECH
281:デフォルトの名無しさん
08/01/25 23:18:56
>>273
今更だが、部分一致ならfind_ifを使う手もある。
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
struct foo {
std::string name;
};
struct FooNameIs : public std::binary_function<char *, foo, bool> {
bool operator() (const char * match, const foo & f) const {
return (f.name == match);
}
};
int main() {
std::vector<foo> v;
/* vに色々追加するコード*/
std::vector<foo>::iterator it = std::find_if(v.begin(), v.end(),
std::bind1st(FooNameIs(), "ABC"));
return 0;
}
あと、foo * f = new fooしてv.push_back(*f)してるのは、凄く気になる。
次ページ続きを表示1を表示最新レス表示スレッドの検索類似スレ一覧話題のニュースおまかせリスト▼オプションを表示暇つぶし2ch
4812日前に更新/208 KB
担当:undef