c_cpp回答http://segmentfault.com/q/1010000002603632(代码片段)

author author     2023-01-11     251

关键词:

#include <fstream> 
using std::ifstream; using std::ofstream;
#include <string>
using std::string;
#include <vector>
using std::vector;
#include <iostream>

vector<string> &split( const string &str, const string &delimiters, vector<string> &elems, bool skip_empty = true ) 
    string::size_type pos, prev = 0;
    while ( ( pos = str.find_first_of(delimiters, prev) ) != string::npos ) 
        if ( pos > prev ) 
            if ( skip_empty && 1 == pos - prev ) break;
            elems.emplace_back( str, prev, pos - prev );
        
        prev = pos + 1;
    
    if ( prev < str.size() ) elems.emplace_back( str, prev, str.size() - prev );
    return elems;


bool pickup(const string &source, const string &dest, const string &label_front, const string &label_back) 
    ifstream ifs( source );
    if ( ifs.fail() ) return false;
    
    ofstream ofs( dest );
    if ( ofs.fail() ) return false;
    
    for ( string line; std::getline(ifs, line); ) 
        vector<string> content;
        if ( 3 == split( line, "[]", content ).size() && content[0] == label_front && content[2] == label_back ) 
            ofs << content[1] << " ";
    
    
    return true;


int main()

    if ( pickup("A.txt", "B.txt", "fullText", "rating") )
        std::cout << "pickup success!" << std::endl;

c_cpp回答问题http://www.zhihu.com/question/26165061(代码片段)

查看详情

c_cpp^(代码片段)

查看详情

c_cpp界()(代码片段)

查看详情

c_cpp输入(代码片段)

查看详情

c_cpp分类(代码片段)

查看详情

c_cpp访问(代码片段)

查看详情

c_cpp填()(代码片段)

查看详情

c_cpp阵列(代码片段)

查看详情

c_cpp功能(代码片段)

查看详情

c_cpp包括(代码片段)

查看详情

c_cpp延缓(代码片段)

查看详情

c_cpp冒泡(代码片段)

查看详情

c_cpp向量(代码片段)

查看详情

c_cpp加(代码片段)

查看详情

c_cpp测试(代码片段)

查看详情

c_cpp318(代码片段)

查看详情

c_cpp10171(代码片段)

查看详情

c_cpp10765(代码片段)

查看详情