C++ C++;-制作一个字符串+;整数集stl类型

C++ C++;-制作一个字符串+;整数集stl类型,c++,types,stl,set,multiset,C++,Types,Stl,Set,Multiset,我的问题是:是否可以创建多类型stl集?如果要从文本文件计算引用次数,我该怎么做?我只需要使用或 #include <set> #include <algorithm> #include <iterator> #include <iostream> #include <cstdlib> #include <fstream> using namespace std; int main() { set<stri

我的问题是:是否可以创建多类型stl集?如果要从文本文件计算引用次数,我该怎么做?我只需要使用或

#include <set>
#include <algorithm>
#include <iterator>
#include <iostream>
#include <cstdlib>
#include <fstream>

using namespace std;

int main()
{
    set<string, int> danteh;
    set<string>::iterator iterator_danteh;
    ifstream d1("text.txt");
    ofstream d2("output.txt");
    string word;
    while(!d1.eof())
    {
        d1 >> word;
        danteh.insert(word);

    }

    cout << endl;
    cout << "FINE!";
    return 0;
}
#包括
#包括
#包括
#包括
#包括
#包括
使用名称空间std;
int main()
{
设丹蒂;
迭代器迭代器;
ifstream d1(“text.txt”);
流d2(“output.txt”);
字符串字;
而(!d1.eof())
{
d1>>单词;
danteh.插入(单词);
}
不能使用from
标题,如:

std::map< std::string, int > danteh ;  // Key is the std::string, 
                                       //  value is the int

要在映射中进行迭代,请在将其用于set时使用迭代器,差异是
first
(键)将为您提供单词,而
second
(值)将为您提供频率。

您可以使用
std::multiset
而不是
std::set
multiset
在同一标题中定义:

#include <set>
生成集合后,可以使用以下命令检索给定单词的出现次数:

danteh.count("hello");

您可能希望改用std::map(另外:不要为eof测试流,而是为成功提取测试流)
std::multiset<std::string> danteh;
...
while(!d1.eof())
{
    d1 >> word;
    danteh.insert(word);
}
danteh.count("hello");