- 论坛徽章:
- 0
|
我使用set作为容器存放字符串,且写了一个仿函数DSort用于set的排序,插入数据后,使用迭代器访问可以遍历容器中的内容,但find却不能成功。请高手指教!(我用VC++ 6.0 开发的)
- #include <map>;
- #include <set>;
- #include <vector>;
- #include <string>;
- #include <fstream>;
- #include <assert.h>;
- using namespace std;
- class DSort
- {
- public:
- DSort(){};
- bool DSort::operator() (const string &str1 ,const string &str2) const {return str1.size() >;= str2.size() ;}
- virtual ~DSort(){};
- };
- using namespace std;
- int main(int argc, char* argv[])
- {
- set<string ,DSort>; setbydsort;
- setbydsort.insert("a");
- setbydsort.insert("bb");
- setbydsort.insert("ccc");
- set<string ,DSort>;::iterator its;
- //for(its = setbydsort.begin() ; its != setbydsort.end() ; ++its)
- //{
- // cout<<*its<<endl;
- //}
- if((its = setbydsort.find("ccc") ) != setbydsort.end())
- {
- cout<<*its<<endl;
- }
- else
- {
- cout<<"Not Find!"<<endl;
- }
- }
复制代码 |
|