Life & Code

代码是咒语,我是魔法师

详细解说STL系列之string之家庭作业. 哈哈. :)

家庭作业:

#include <string>
#include <iostream>
#include <algorithm>
#include <vector>
#include <fstream>
using namespace std;

int _tmain(int argc, _TCHAR* argv[])
{
        ifstream in("c:\\teststring.txt" ) ;

        string  strtmp;
        string  strset = "| ,";

        while(getline(in, strtmp, '\n'))
        {
                size_t pos1 = 0;
                size_t pos2 = 0;
                while(true)
                {
                        pos1 = strtmp.find_first_not_of(strset,pos2);
                        if( pos1 == string::npos)
                                break;
                        pos2 = strtmp.find_first_of(strset,pos1);
                        cout << strtmp.substr(pos1, pos2 - pos1 )<<"  ";
                }
                cout <<endl;
        }
        return 0;
}

//c:\\teststring.txt
张三|3456123, 湖南
李四,4564234| 湖北
王小二, 4433253|北京

posted on 2006-04-11 11:33 橙子 阅读(259) 评论(0)  编辑 收藏 引用 所属分类: C++ & STL


只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理


<2006年4月>
2627282930311
2345678
9101112131415
16171819202122
23242526272829
30123456

导航

统计

常用链接

留言簿(10)

随笔分类

随笔档案

相册

收藏夹

搜索

最新评论

阅读排行榜