首页 > 编程语言 > 详细

C++ set 使用范例

时间:2021-01-03 21:43:29      阅读:39      评论:0      收藏:0      [点我收藏+]
#include <iostream>
#include <string>
#include <set>
#include <sstream>
using namespace std;

set<string> dict; // string 集合

int main()
{
    string s, buf;
    while (cin >> s)
    {
        for (int i = 0; i < s.length(); i++)
        {
            if (isalpha(s[i]))
                s[i] = tolower(s[i]);
            else
                s[i] = ‘ ‘;
        }
        stringstream ss(s);
        while (ss >> buf)
            dict.insert(buf);
    }
    for (set<string>::iterator it = dict.begin(); it != dict.end(); it++)
        cout << *it << "\n";
    return 0;
}

C++ set 使用范例

原文:https://www.cnblogs.com/fanlumaster/p/14226760.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!