您的位置:首页 > 其它

批量生成文件并写入大量内容

2013-12-05 10:07 756 查看
// CreatFile.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include <iostream>
#include<fstream>
#include <string>
using namespace std;

void createFile(string name,string content){

string path="d:\\"+name+".txt";
ofstream f1(path);
if(!f1)return;
f1<<content<<endl;
f1.close();
}

int _tmain(int argc, _TCHAR* argv[])
{
string  titles[]={"Hinit","HRest1","HRest2","HRest3","HRest4"};
string content[5];
string words[]={"yi","er","san","si","wu","liu","qi","ba","jiu","shi","zou","ting","zuo","zhan","ting1","kan","qianjin",
"houtui","zuozhuan","youzhuan","houzhuan","qili","xiadun","huishou","tiaowu","changge","dingwei","shibie",
"daiji","shuohua","taitou","xingzou","tingzhi","zhuantou","dazhaohu","dataiji","wangqianzou","xianghoutui",
"xiangzuozhuan","xiangyouzhuan","zhaoshengyin","jirenlian","yiyanbufa","chayanguanse","shanqiyingren","wenjiqiwu",
"ertingbafang","taotaobujue","shouzhudaitu","zuoguyoupan"};

for(int j=0;j<50;j++){
content[0]+="Hinit -A -D -T 1 -S training/trainlist_"+words[j]+".txt -M model/hmm0 -H model/proto/hmm_"+words[j]+" -l "+words[j]+" -I training/lab_"+words[j]+".mlf "+words[j]+"\n";
content[1]+="HRest -A -D -T 1 -S training/trainlist_"+words[j]+".txt -M model/hmm1 -H model/hmm0/hmm_"+words[j]+" -l "+words[j]+" -I training/lab_"+words[j]+".mlf "+words[j]+"\n";
content[2]+="HRest -A -D -T 1 -S training/trainlist_"+words[j]+".txt -M model/hmm2 -H model/hmm1/hmm_"+words[j]+" -l "+words[j]+" -I training/lab_"+words[j]+".mlf "+words[j]+"\n";
content[3]+="HRest -A -D -T 1 -S training/trainlist_"+words[j]+".txt -M model/hmm3 -H model/hmm2/hmm_"+words[j]+" -l "+words[j]+" -I training/lab_"+words[j]+".mlf "+words[j]+"\n";
content[4]+="HRest -A -D -T 1 -S training/trainlist_"+words[j]+".txt -M model/hmm4 -H model/hmm3/hmm_"+words[j]+" -l "+words[j]+" -I training/lab_"+words[j]+".mlf "+words[j]+"\n";
}

for(int j=0;j<5;j++){
createFile(titles[j],content[j]);
}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: