ブーストで文字列をカンマで分割

http://www.kab-studio.biz/Programing/Codian/STL/02.html
ブーストで文字列をカンマで分割

#include <iostream>
#include <vector>
#include <boost/algorithm/string.hpp>
using namespace std;
int main(){

        string str="abc,efg,hij";
        vector<string> v;
        boost::algorithm::split(v,str,boost::is_any_of(","));
        cout << v[1];
        return 0;
}

間違ってても突き進む。

#include <iostream>
#include <vector>
#include <boost/algorithm/string.hpp>
using namespace std;
int main(){
     setlocale(LC_CTYPE,"");
        basic_string<wchar_t> str=L"abc,efg,hij";
        vector<basic_string<wchar_t> > v;
        boost::algorithm::split(v,str,boost::is_any_of(L","));
        wcout << v[1];
        return 0;
}
#include <iostream>
#include <vector>
#include <boost/algorithm/string.hpp>
using namespace std;
int main(){
     setlocale(LC_CTYPE,"");
        basic_string<wchar_t> str=L"テスト,cfg,テスト2";
        vector<basic_string<wchar_t> > v;
        boost::algorithm::split(v,str,boost::is_any_of(L","));
        wcout << v[1];
        return 0;
}

これは実行はできる

#include<iostream>
#include<string>
#include<vector>
#include<boost/algorithm/string.hpp>

using namespace std;

int main(){
        setlocale(LC_CTYPE,"");
        cout << "hello" << "\n";
        wstring IP=L"たぬき.168.きつね.1";

        vector<wstring> v;
                boost::algorithm::split(v,IP,boost::is_any_of(L"."));


        wcout << v[3];
}

grepっぽいやつ
元ファイル all
検索単語 list1.txt

#include <iostream>
#include <locale>
#include <vector>
#include <string>
#include<stdlib.h>
#include<fstream>
#include<boost/algorithm/string.hpp>
#include<time.h>
#include<sstream>

using namespace std;


int main(){
        int i,j,lll;
        time_t now=time(NULL);
        lll=0;
        setlocale(LC_CTYPE,"");
        std::basic_string<wchar_t> str;
        std::wifstream ifs("../all");
//      std::wifstream ifs("test.txt");
        std::wifstream ifs2("../list.txt");

        stringstream ss;
//      std::wifstream ifs2("tmp.txt");
        std::vector< basic_string<wchar_t> > v;
        std::vector< vector<basic_string<wchar_t> > > table1;
        std::vector< basic_string<wchar_t> > list1;
        std::vector < basic_string<wchar_t> > v2;
//      std::wifstream ifs("tweet0");
        i=0;
        while(getline(ifs2,str)){
                list1.push_back(str);
                v2.clear();
                 table1.push_back(v2);
//              cout << i << "\n";
                i++;
        }

//      vector<basic_string<wchar_t> > q;
//      table1[0]=q;
//      table1[0].push_back(L"heeloo");
//      exit(1);

//      for(i=0;i<=(list1.size()-1);i++){
//      }

        while(getline(ifs,str)){
                if(lll%100000==0){

                        wcout <<L"###"<< time(NULL)-now<<" "<< (double)lll/(double)179282135<<L"\n";
                }

///             wcout << str << "\n";
                boost::algorithm::split(v,str,boost::is_any_of(L"\x01"));
                if(v.size()==4){
                //      wcout << v[2]<<"\n";
                        for(i=0;i<=(list1.size()-1);i++){
                                j= str.find(list1[i]);

                                if(j!=string::npos){
                                        //wcout <<str << "\n";
                                        //wcout <<str<<"\n";
                                        //cout << i << "\n";
                                        table1[i].push_back(v[0]+L"\x01"+v[1]+L"\x01"+v[2]+L"\x01"+v[3]);
                                }else{

                                        //cout << "no" << "\n";
                                }
                                //wcout << list1[i]  ;
                }
                //wcout << str <<L"3文字目:"<< str[2] <<"\n";
                }
                lll++;

        }

        //cout << counta << "\n";



        for(i=0;i<=(list1.size()-1);i++){

                   ss.str("");
                    ss.clear(stringstream::goodbit);

                ss << i << ".csvcsv";
                //cout << ss.str();
                std::wofstream ifs3(ss.str().c_str());

                if(table1[i].size()>0){
                        for(j=0;j<=(table1[i].size()-1);j++){

                                wcout << i<< L",,," << table1[i][j] << L",,," << list1[i] << "\n";

                                ifs3 << table1[i][j] << "\n";
                        }
//                      cout << i << "\n";
                        //wcout << i << L",,," << table1[i][j] << "\n";
                }
                ifs3.close();

        }

}



grep的なものファイル随時出力版。

include <iostream>
#include <locale>
#include <vector>
#include <string>
#include<stdlib.h>
#include<fstream>
#include<boost/algorithm/string.hpp>
#include<time.h>
#include<sstream>

using namespace std;


int main(){
        int i,j,lll,ii;
        time_t now=time(NULL);
        lll=0;
        setlocale(LC_CTYPE,"");
        std::basic_string<wchar_t> str;
        std::wifstream ifs("../all");
//      std::wifstream ifs("../test.txt");
        std::wifstream ifs2("../list.txt");

        stringstream ss;
//      std::wifstream ifs2("../tmp.txt");

        std::vector< basic_string<wchar_t> > v;
        std::vector< vector<basic_string<wchar_t> > > table1;
        std::vector< basic_string<wchar_t> > list1;
        std::vector < basic_string<wchar_t> > v2;
        std::vector < wofstream* > ofs;
//      std::wifstream ifs("tweet0");
        i=0;
        while(getline(ifs2,str)){
                list1.push_back(str);
                v2.clear();
                 table1.push_back(v2);


                  ss.str("");
                  ss.clear(stringstream::goodbit);
                  ss << i+1 << ".csvcsv";
                //cout << ss.str();
                std::wofstream* f= new std::wofstream(ss.str().c_str(),std::ios::app);

                ofs.push_back(f);
                //ofs.push_back(new wofstream(ss.str().c_str(),std::ios::app));

                //ofs.push_back(ifs3);
//              ofs.push_back(new wofstream(ss.str().c_str()));
//              ifs3.close();
                //delete ifs3;
                //cout << i << "\n";
                i++;
        }
        int listno=list1.size();
//      exit(1);
//      vector<basic_string<wchar_t> > q;
//      table1[0]=q;
//      table1[0].push_back(L"heeloo");
//      exit(1);

//      for(i=0;i<=(list1.size()-1);i++){
//      }

        while(getline(ifs,str)){
                if(lll%100000==0){

                        wcout <<L"###"<< (int)time(NULL)-now<<" "<< (double)lll/(double)179282135<<L"\n";

//                      for(ii=0;ii<listno;ii++){

                                //(*(ofs[i])).flush();
//                      }
                }

///             wcout << str << "\n";
                boost::algorithm::split(v,str,boost::is_any_of(L"\x01"));
                if(v.size()==4){
                //      wcout << v[2]<<"\n";
                        for(i=0;i<=(list1.size()-1);i++){

                                j= str.find(list1[i]);

                                if(j!=string::npos){
                                        //cout << i << "\n";
                                        //cout << "test\n";
                                        //wcout <<str << "\n";
                                        //wcout <<str<<"\n";
                                //      table1[i].push_back(v[0]+L"\x01"+v[1]+L"\x01"+v[2]+L"\x01"+v[3]);

                                        (*(ofs[i])) <<  v[0]+L"\x01"+v[1]+L"\x01"+v[2]+L"\x01"+v[3]+L"\n" <<flush;

                                }else{

                                        //cout << "no" << "\n";
                                }
                                //wcout << list1[i]  ;
                }
                //wcout << str <<L"3文字目:"<< str[2] <<"\n";
                }
                lll++;

        }

        //cout << counta << "\n";



        for(i=0;i<=(list1.size()-1);i++){

                   ss.str("");
                    ss.clear(stringstream::goodbit);

                ss << i << ".csvcsv";
                //cout << ss.str();
                //std::wofstream ifs3(ss.str().c_str());

                if(table1[i].size()>0){
                        for(j=0;j<=(table1[i].size()-1);j++){

//                              wcout << i<< L",,," << table1[i][j] << L",,," << list1[i] << "\n";

//                              ifs3 << table1[i][j] << "\n";
                        }
//                      cout << i << "\n";
                        //wcout << i << L",,," << table1[i][j] << "\n";
                }
//              ifs3.close();

        }

        //flush();

        for(i=0;i<listno;i++){


//              (*(ofs[i])).flush();

        }
        cout << listno <<"\n";
}