现在我完全糊涂了。我整天都在谷歌搜索,但仍然不明白为什么这段代码不起作用。
我有,vector
那些structs
有财产。当我想在 中添加一个新的时,首先我必须检查具有相同属性的 a 是否已经存在。如果是,则不会添加。structs
string
struct
vector
struct
string
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
struct Try{
string name;
Try( string name) : name ( name ) { }
bool operator < ( const Try & a ) const
{
return name < a . name;
}
};
int main(){
vector<Try> vektor;
Try *n;
vektor . push_back( Try( "Prague" ) );
n = new Try( "Brno" );
vector<Try>::iterator it = lower_bound( vektor . begin(), vektor . end(), n -> name);
if( it == vektor . end() ){
cout << "not included" << endl;
cout << it -> name << endl;
}
else
cout << "included" << endl;
return 0;
}