从字符串中获取单词频率的方法?

时间:2016-05-31 19:40:02

标签: c++ curl

嘿伙计我有以下问题。我一直在使用C ++来搜索网站,在outputHTML中查找5个最常用的字符串。目前我有以下代码。任何提示都会很棒。

curl = curl_easy_init();
if(curl) {
    curl_easy_setopt(curl, CURLOPT_URL, "http://example.com");
    curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, WriteCallback);
    curl_easy_setopt(curl, CURLOPT_WRITEDATA, &htmlOutput);
    res = curl_easy_perform(curl);
    curl_easy_cleanup(curl);

    std::cout << htmlOutput << std::endl;
}

1 个答案:

答案 0 :(得分:2)

以下是一些更令人敬畏的提示:

std::istringstream awsome_stream(web_text);
std::string word;
std::map<std::string, unsigned int> kewl_words;
while (awsome_stream >> word)
{
  kewl_words[word]++;
}
std::cout << "Occurances of 'div': " << kewl_words["div"] << "\n";