遍历文件,寻找 struct 结构体
时间:2020-01-06
本文章向大家介绍遍历文件,寻找 struct 结构体,主要包括遍历文件,寻找 struct 结构体使用实例、应用技巧、基本知识点总结和需要注意事项,具有一定的参考价值,需要的朋友可以参考一下。
代码暂时不完善,只实现了基本逻辑,字符串判断逻辑有缺陷
#include "iostream" #include "fstream" #include "io.h" #include "string" #include "direct.h" #include "stdio.h" #define NORMAL 0 #define ERROR -1 using namespace std; class Struct_Export { public: Struct_Export(const char* pathout) { setOutfile(pathout); } ~Struct_Export() { ; } int Struct_Export_Action() { } void setOutfile(const char * path) { Outfile = string(path); } string getOutfile() { return Outfile; } int FindStructFromFile(const char* path) { ifstream infile; ofstream outfile; string data; size_t index; infile.open(path); outfile.open(getOutfile().c_str(), ios::app); while (!infile.eof()) { getline(infile, data); if ((index = data.find("struct")) != string::npos) //找到struct起始位置 { string substr = data.substr(index + 6, data.length()); if (substr.find("{") != string::npos ) { outfile << data << endl; while (!infile.eof()) //打印当前struct的内容至output文件 { getline(infile, data); outfile << data << endl; if (data.find("}") != string::npos) //打印至 } 结尾 { break; } } outfile << endl; } } } infile.close(); return NORMAL; } int FindFileFromDir(const char* strPath) { int iRet = 0; intptr_t handle; _finddata_t findData; handle = _findfirst(strPath, &findData); if (handle == -1) { cout << "Failed to find first file!\n" << endl; return NULL; } do { if (findData.attrib & _A_SUBDIR && !(strcmp(findData.name, ".") == 0 || strcmp(findData.name, "..") == 0)) { string subdir(strPath); subdir.insert(subdir.find("*"), string(findData.name) + "\\"); FindFileFromDir(subdir.c_str()); } else if((strcmp(findData.name, ".") != 0 && strcmp(findData.name, "..") != 0)) { string file_pathname(strPath); file_pathname = file_pathname.substr(0, file_pathname.length() - 3) + string(findData.name); iRet = FindStructFromFile(file_pathname.c_str()); if (iRet != NORMAL) { cout << "Call FindStrctFromFile failed!\n" << endl; return ERROR; } } } while (_findnext(handle, &findData) == 0); return NORMAL; } private: string Outfile; }; int main(int argc, char* argv[]) { if (argc < 3) { cout << "Struct_export must have input!" << endl; cout << "Struct_export -dir pathname" << endl; exit(1); } int iRet = 0; string dir = string(argv[2]); char Output[_MAX_PATH]; _getcwd(Output, _MAX_PATH); if (dir[dir.length()] != '\\') { dir = dir + '\\'; } dir = dir + "*.*"; Struct_Export Export_Acion( (string(Output)+string("\\stoutput.txt")).c_str() ); if (!strcmp(argv[1], "-dir")) { iRet = Export_Acion.FindFileFromDir(dir.c_str()); if (iRet != NORMAL) { cout << "Call Export_Acion.FindFileFromDir failed!" << endl; } } return 0; }
原文地址:https://www.cnblogs.com/xuyong437/p/12156269.html
- mongodb 速成笔记
- oAuth 2.0 笔记
- JavaScript内置对象--Math对象
- oAuth 2.0 笔记
- common-pool2 学习:thrift连接池的另一种实现
- IntelliJ IDEA 17和Maven构建javaWeb项目
- spring-boot 速成(2) devtools之热部署及LiveReload
- spring-boot 速成(2) devtools之热部署及LiveReload
- 使用git提交项目
- JavaScript中的内置对象--Number对象
- 自动驾驶落地,究竟被什么绑住了脚?
- JDBC(三)数据库连接池(DBCP、C3P0)
- Single Page Application概览
- HashSet集合中hashCode及equals方法详解
- JavaScript 教程
- JavaScript 编辑工具
- JavaScript 与HTML
- JavaScript 与Java
- JavaScript 数据结构
- JavaScript 基本数据类型
- JavaScript 特殊数据类型
- JavaScript 运算符
- JavaScript typeof 运算符
- JavaScript 表达式
- JavaScript 类型转换
- JavaScript 基本语法
- JavaScript 注释
- Javascript 基本处理流程
- Javascript 选择结构
- Javascript if 语句
- Javascript if 语句的嵌套
- Javascript switch 语句
- Javascript 循环结构
- Javascript 循环结构实例
- Javascript 跳转语句
- Javascript 控制语句总结
- Javascript 函数介绍
- Javascript 函数的定义
- Javascript 函数调用
- Javascript 几种特殊的函数
- JavaScript 内置函数简介
- Javascript eval() 函数
- Javascript isFinite() 函数
- Javascript isNaN() 函数
- parseInt() 与 parseFloat()
- escape() 与 unescape()
- Javascript 字符串介绍
- Javascript length属性
- javascript 字符串函数
- Javascript 日期对象简介
- Javascript 日期对象用途
- Date 对象属性和方法
- Javascript 数组是什么
- Javascript 创建数组
- Javascript 数组赋值与取值
- Javascript 数组属性和方法
- Day10.高阶函数介绍
- python提示警告InsecureRequestWarning
- Day11.类和对象这回事儿
- Day12.魔法方法&方法重写
- Linux基础第一课——基础知识了解
- 【Vue CLI】手把手教你撸插件
- Linux基础第二课——系统架构
- Day13.继承&多态
- Linux第三课——目录操作
- Linux基础第四课——文件操作
- Linux基础第五课——用户管理
- Linux基础第六课——grep|awk|sort|uniq
- Python向上取整,向下取整以及四舍五入函数
- 使用requests模块post payload请求
- 解决HTTP status code is not handled or not allowed