【C++】STL(Standard Template Library)相談室 8at TECH
【C++】STL(Standard Template Library)相談室 8 - 暇つぶし2ch281:デフォルトの名無しさん
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