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

详细解说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|北京

你可能感兴趣的:(详细解说STL系列之string之家庭作业. 哈哈. :))