C++文件io_将少于1000行的歌词文件(.srt)清理成纯的文字,不包含视频时间信息的txt文件。

#include <iostream>
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <fstream>
using namespace std;

//将少于1000行的歌词文件(.srt)清理成纯的文字,不包含视频时间信息的txt文件。
int main(int argc,char** argv)
{
    cout<<"argc = "<<argc<<endl;
    for(int i = 0;i<argc;i++){
        cout<<"argv["<<i<<"] = "<< argv[i]<<endl;
    }
    //文件操作
    const char* filename = "text.srt";
    const char* fswname = "newText.txt";
    fstream fs(filename,std::fstream::in);

    fstream fsw(fswname,std::fstream::out | ios_base::trunc );//新建文件保存
	//计算文件长度
    fs.seekg(0,fs.end);
    int lengthFS = fs.tellg();
    fs.seekg(0,fs.beg);

    string strbuf ="hello";
    while(fs.tellg() != lengthFS){
        getline(fs,strbuf,'\n');
        if(strbuf.find("-->") ==  string::npos && strbuf.length()>3){//找不到-->并且大于三个字符的,输出
            cout<<strbuf<<endl;
            fsw<<strbuf<<endl;
        }

    }
    
    fs.close();
    fsw.close();
    return 0;
}

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值