STL练习程序(String...)

#include <string>
#include
#include
#include
#include
using namespace std;

int main()
{
ifstream in("data.txt");
string strtmp;
vector<string> vect;
while (getline(in,strtmp,'\n'))
vect.push_back(strtmp);

copy(vect.begin(),vect.end(),ostream_iterator<string>(cout,"\n"));
cout<
string strset="|, ";
vector<string> v[3];
vector<string>::iterator it;
int i=0;

for (it=vect.begin();it!=vect.end();it++,i++)
{
int first1=it->find_first_of(strset);
int first2=it->substr(first1).find_first_not_of(strset)+first1;
int last1=it->find_last_of(strset);
int last2=it->substr(0,last1).find_last_not_of(strset);

v[i].push_back(it->substr(0,first1));
v[i].push_back(it->substr(first2,last2-first2+1));
v[i].push_back(it->substr(last1+1));
}

for (i=0;i<3;i++)
{
copy(v[i].begin(),v[i].end(),ostream_iterator<string>(cout," "));

cout< }

return 0;
}

转载于:https://www.cnblogs.com/tiandsp/archive/2012/02/08/2342544.html

你可能感兴趣的:(STL练习程序(String...))