プログラムをメモします。
#include <vector> #include <iostream> #define BIG_BUFFERSIZE 1024 using namespace std; template <typename List> void split(const std::string& s, const std::string& delim, List& result) { result.clear(); using string = std::string; string::size_type pos = 0; while(pos != string::npos ) { string::size_type p = s.find(delim, pos); if(p == string::npos) { result.push_back(s.substr(pos)); break; } else { result.push_back(s.substr(pos, p - pos)); } pos = p + delim.size(); } } int main(void) { vector<string> strData; while(cin) { string input_line; getline(cin, input_line); cout << input_line << endl; strData.push_back(input_line); }; for(auto i = strData.begin(); i != strData.end(); ++i) { vector<string> split_data; cout << *i << endl; split(*i, ".", split_data); for(auto j = split_data.begin(); j != split_data.end(); ++j) { cout << *j << endl; } } }
入力
192.168.186.70 1 192.168.110.238 - - [10/Jul/2013:18:40:43 +0900] "GET /top.html HTTP/1.1" 404 8922 "http://gi-no.jp" "Mozilla/5.0"
出力
192.168.186.70 1 192.168.110.238 - - [10/Jul/2013:18:40:43 +0900] "GET /top.html HTTP/1.1" 404 8922 "http://gi-no.jp" "Mozilla/5.0" 192.168.186.70 192 168 186 70 1 1 192.168.110.238 - - [10/Jul/2013:18:40:43 +0900] "GET /top.html HTTP/1.1" 404 8922 "http://gi-no.jp" "Mozilla/5.0" 192 168 110 238 - - [10/Jul/2013:18:40:43 +0900] "GET /top html HTTP/1 1" 404 8922 "http://gi-no jp" "Mozilla/5 0"