Lower_bound匹配错误的字符串

时间:2016-03-28 18:50:52

标签: c++ struct lower-bound

现在我完全糊涂了。我一整天都在谷歌搜索,仍然无法理解为什么这段代码无法正常工作。

vector structsstructs 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; } 是否已存在。如果是,则不会被添加。

namespace Tests
{
   [TestClass()]
   public class MyTests
   {
      [ClassInitialize()]
      public static void Init(TestContext context)
      {
        // mock up HTTP request
        var sb = new StringBuilder();
        TextWriter w = new StringWriter(sb);
        var httpcontext = new HttpContext(new HttpRequest("", "http://www.example.com", ""), new HttpResponse(w));

        HttpContext.Current = httpcontext;

      }
      [TestMethod()]
      public void webSerivceTest()
      {
        // the httpcontext will be already set for your tests :)
      }
   }
}

1 个答案:

答案 0 :(得分:1)

尝试使用此功能,它是标准new Gson().fromJson(jsonString,Response.class); 的变体。如果在范围内找到值,则返回匹配元素的迭代器('最低'一个),当没有匹配时,迭代器返回等于binary_search()(通常为last):

end()