这是我第一次尝试使用tr1。我想制作一个大约50000个单词的字典,只需要查找单词字符串,如果找到它就会返回类似bool的东西。我试图理解我找到的这段代码。
有人可以告诉我,我这里有什么是朝着我的目标迈出的良好开端吗?
在50000字词典中,我可以期待什么样的表现呢?
另外,有人可以向我解释这行代码吗?
found = it != words.end();
我之前从未见过这种语法。
typedef std::tr1::unordered_set<std::string> Dictionary;
Dictionary words;
std::ifstream word_is("eng_dict.txt");
std::copy(std::istream_iterator<std::string>(word_is),
std::istream_iterator<std::string>(),
std::inserter(words, words.begin()));
Dictionary::const_iterator it = words.find("hello");
found = it != words.end();
谢谢!
答案 0 :(得分:1)
TR1是旧东西 - 从2005年左右开始 - 大多数(如果不是全部)现在都是C ++ 11的一部分,并且不需要使用过时的{{1}比特了。无论您使用哪种资源包含此代码,请帮自己一个忙,然后把它扔掉。获得更现代的书。
关于表现问题,我们不清楚你真正想要的答案是什么,或真正的问题是什么。我会给你标准答案:&#34; 尝试并找出答案。&#34;
关于问题re:语法:
tr1
如果我这样改写它会有帮助吗?
found = it != words.end();
为了将来参考,您可以查阅C++ Operator Precedence Table。