c++ 文本处理


c++ 文本处理

1、使用sstream版本

(1)功能:截取第一列为1以后的数据,如下图,截取第5行(包括第5行)以后的数据,前面4行数据丢弃。

(2)代码:textProc.cc

#include 
#include 
#include 
#include 

using namespace std;

int main(int argc, char *argv[]) {// *argv[] 是一个指针数组,也就是一个字符串数组。
    string dir = "/data/";

    string old_file = dir + argv[1] + "/input/txdsp_input_old.dat";
    string gen_file = dir + argv[1] + "/input/txdsp_input.dat";
    string cmd      = "mv ";
    cmd             = cmd + gen_file + " " + old_file;

    if(system(cmd.c_str()) == 0) {
        cout<<"file move ok !"<>word;              // 利用string流一个一个单词的读取, 这里只读一个帧头标识。

        if(word == "1") {       // 将找到帧头后的所以数据都输出。
            os<

2、regex版本

#include 
#include 
#include 
#include 

using namespace std;

int main(int argc, char *argv[]) {// *argv[] 是一个指针数组,也就是一个字符串数组。
    string dir = "/data/";

    string old_file = dir + argv[1] + "/input/txdsp_input_old.dat";
    string gen_file = dir + argv[1] + "/input/txdsp_input.dat";
    string cmd      = "mv ";
    cmd             = cmd + gen_file + " " + old_file;

    if(system(cmd.c_str()) == 0) {
        cout<<"file move ok !"<

输出:

相关