文件处理_保留版_项目中用到
2012-05-19 11:03
260 查看
/********************************************************************** 作者:David Bao 时间:2012年3月15日 描述:读取6个表情特征文本,转成两个arff格式文件,输入到weka测试 ***********************************************************************/ #include <string> #include <stdlib.h> #include <stdio.h> #include <iostream> #include <fstream> #include <sstream> #define N 6 using namespace std; void main() { string FileName; char name[30]; fstream InFile; ofstream OutFile_train("D:\\1\\W_train.arff"); if(OutFile_train.is_open()) { cout <<"W_train opened !"<<endl; } ofstream OutFile_test("D:\\1\\W_test.arff"); if(OutFile_test.is_open()) { cout << "W_test opened !"<<endl; } //训练集****************************************** OutFile_train<<"@relation 'FER'"<<endl; char *ch1 = new char; for(int i=1;i<=300;i++) { itoa(i,ch1,10); OutFile_train<<"@attribute feature"+string(ch1)+" real"<<endl; } OutFile_train << "@attribute 'class' {angry,disgust,fear,happy,sad,surprise}"<<endl; OutFile_train << "@data" << endl; //测试集****************************************** OutFile_test<<"@relation 'FER'"<<endl; char *ch2 = new char; for(int i=1;i<=300;i++) { itoa(i,ch2,10); OutFile_test<<"@attribute feature"+string(ch2)+" real"<<endl; } OutFile_test << "@attribute 'class' {angry,disgust,fear,happy,sad,surprise}"<<endl; OutFile_test << "@data" << endl; //遍历6个表情文件************************************* //6个文件 for(int i=1; i<=N; i++) { itoa(i,name,10); FileName = string("C:\\Users\\user\\Desktop\\data2\\")+name; FileName += string(".txt"); //cout << FileName.c_str() <<endl; InFile.open(FileName.c_str(),ios::in); if(InFile.is_open()) { cout <<FileName.c_str()<<"已打开啦!"<<endl; } //每个文件有600行 string line; int HangHao=0; bool flag = true; while(getline(InFile,line)) { HangHao++; istringstream stream(line); string word; if(flag) { while(stream >> word) { OutFile_train << word.c_str() << ","; } } else { while(stream >> word) { OutFile_test << word.c_str() << ","; } } if(HangHao%30==0) { if(flag) { switch(i) { case 1: OutFile_train << "angry"<<endl; break; case 2: OutFile_train << "disgust"<<endl; break; case 3: OutFile_train << "fear"<<endl; break; case 4: OutFile_train << "happy"<<endl; break; case 5: OutFile_train << "sad"<<endl; break; case 6: OutFile_train << "surprise"<<endl; break; } } else { switch(i) { case 1: OutFile_test << "angry"<<endl; break; case 2: OutFile_test << "disgust"<<endl; break; case 3: OutFile_test << "fear"<<endl; break; case 4: OutFile_test << "happy"<<endl; break; case 5: OutFile_test << "sad"<<endl; break; case 6: OutFile_test << "surprise"<<endl; break; } } flag = (!flag); } } InFile.close(); InFile.clear(); } OutFile_train.close(); OutFile_test.close(); system("pause"); }
相关文章推荐
- 文件处理_项目中用到_保存版
- Linux企业级项目实践之网络爬虫(5)——处理配置文件
- 2015年大一下第14周项目1-用二进制文件处理学生成绩
- 【Android】Android项目中R文件找不到怎么处理?
- 学习总结:即时通讯项目里面的语音处理-文件模式录音
- 第十六周项目 用二进制文件处理学生成绩
- 项目49-用二进制文件处理学生成绩
- android 项目进行混淆时,签名打包生产proguard文件是报错处理方法。
- C++第16周(春)项目1 - 用二进制文件处理学生成绩
- IIS7.5配置Asp.net项目出现HTTP 错误 404.17 - Not Found 请求的内容似乎是脚本,因而将无法由静态文件处理程序来处理。
- Redis文件事件处理用到的基本数据结构视图
- Linux企业级项目实践之网络爬虫(5)——处理配置文件
- Rollup处理并打包JS文件项目实例代码
- 第15周项目1-用二进制文件处理学生成绩
- 第十五周项目1:用二进制文件处理学生成绩
- 第十五周项目1-用二进制文件处理学生成绩
- 第17周项目6-文件读取成绩进行处理
- 第十五周项目1 用二进制文件处理学生成绩
- 做国际项目时候,处理翻译的国际化资源文件的java代码
- 关于ansible删除某文件夹下面所有文件,并保留文件的处理办法