小编Kth*_*ieu的帖子

C++中的字典使用没有值的Map,只有键

我正在为c ++中的单词实现某种查找,虽然实现地图的代码在那里,但我想确保它是否能够使用带有键和值的映射作为std :: string,并且仅使用键作为没有返回值的查找.

    std::vector< std::string> DictionLines;
    Reader DictionReader(Dictionary);
    DictionLines = DictionReader.getLines();
    std::map<std::string, std::string> DictionaryM;

    for (int t = 0; t < DictionLines.size(); ++t) {
        DictionaryM.insert(std::pair<std::string, std::string>(DictionLines.at(t), DictionLines.at(t)));
    }
Run Code Online (Sandbox Code Playgroud)

此代码接收Dictionary.txt文件中的349900个单词,并将它们存储在地图中.字典的每一行都是要查找的单词; 没有定义或任何关联的价值.这就是为什么我认为在地图中存储一对相同的键和值是可以的,并且使用find和first/second也可以.请确认.

c++ dictionary

10
推荐指数
1
解决办法
7526
查看次数

标签 统计

c++ ×1

dictionary ×1