zoukankan      html  css  js  c++  java
  • uva10815 by sixleaves

    题目很简单。其实stringstream就的用法和iosteam差不多,所以学习起来是很简单的。stringstream类里面有一个string缓存,str()和str(string)成员函数。
    前者用于把stringstream的返回string缓存,后者是把string对象包装成stringstream对象。stringstream类存在于sstream头文件中。其是独立于标准I/O但有类似
    功能的类。clear主要是为了多次使用stringstream,因为stringstream每次的构造都十分耗时,所以最后能多次,反复使用,就如同面向对象里面的单例模式。
    代码如下:
     1 #include <iostream>
     2 #include <string>
     3 #include <set>
     4 #include <sstream>
     5 
     6 
     7 using namespace std;
     8 
     9 set<string> dict;
    10 stringstream ss;
    11 
    12 /*
    13  主要学习两个重点stringstream的用法与set容器的insert、迭代器的用法。
    14  */
    15 int main() {
    16 
    17     string s,buf;
    18     
    19     while (cin >> s) {
    20         int len = s.size();
    21         for (int i = 0; i < len; i++) {
    22             if (isalpha(s[i])) s[i] = tolower(s[i]); else s[i] = ' ';
    23         }
    24         ss.clear();
    25         ss.str(s);
    26         while (ss >> buf) dict.insert(buf);
    27     }
    28     
    29     for (set<string>::iterator it = dict.begin(); it != dict.end(); ++it)
    30         cout << *it << endl;
    31     return 0;
    32 }
  • 相关阅读:
    获得每天的日期流水 函数
    sql调用web服务
    Sql 查询当天、本周、本月记录
    从首页问答标题到问答详情页
    首页列表显示全部问答,完成问答详情页布局
    制作首页的显示列表。
    发布功能完成
    登录之后更新导航
    完成登录功能,用session记住用户名
    完成注册功能
  • 原文地址:https://www.cnblogs.com/objectc/p/4553498.html
Copyright © 2011-2022 走看看