解析txt文件,赋值结构体数组
来源:互联网 发布:软件字体乱码 编辑:程序博客网 时间:2024/06/15 21:56
qt可以利用自己的库来解析txt文件,赋值到数组中供程序使用,代码如下
首先定义一个数组,比如
struct s_write_file { QByteArray * ptr_file; QString name; QString city; unsigned int age;};
在程序中
unsigned int all_count = 0;s_write_file w_file[32];
void Widget::ReadFile(){ QFile fileRead("/mnt/info.txt"); fileRead.open(QFile::ReadOnly | QFile::Text); QTextStream in(&fileRead); QString strContent=""; int file_num= 0; while(!in.atEnd()) { strContent += in.readLine(); file_num++; } fileRead.flush(); fileRead.close(); // s_write_file w_file[W_FILE_NUM]; //此处可以判断txt的行数来判断数组的参数个数,不需要直接开w_file[32] QStringList strlist = strContent.split(";"); //利用;来间隔 for(int i=0;i<strlist.count();i++) { QStringList strstrlist=strlist.at(i).split("#");//利用#来间隔 for(int j=0;j<strstrlist.count();) { QString file = strstrlist.at(j++).toLocal8Bit().data(); QString md5 = strstrlist.at(j++).toLocal8Bit().data(); QString age_String =strstrlist.at(j++).toLocal8Bit().data(); int age = age_String.toInt(0,10); //10进制计数 w_file[all_count].ptr_file = NULL; w_file[all_count].name = file; //qDebug() << w_file[all_count].name; w_file[all_count].city = city; //qDebug() << w_file[all_count].city; w_file[all_count].age= age; //qDebug() << w_file[all_count].age; all_count++; } }}
wangxiaohong#beijing#20;zhangxiaolei#shanghai#16;huxiaohei#guangzhou#25;lixiaoming#shanxi#32;huangxiaohu#zhejiang#29;zhaoxiaoling#chongqing#26
0 0
- 解析txt文件,赋值结构体数组
- 解析INI文件,赋值结构体数组
- 数组 结构体的赋值
- c++ 结构体数组赋值
- PHP读取txt文件的内容并赋值给数组
- 结构体读写txt文件
- C语言结构体数组赋值问题
- C++结构体数组赋值问题
- 数组直接赋值给结构体
- 结构体变相实现数组赋值
- 给char数组或者结构体赋值
- 结构体初始化中的数组赋值
- 数组结构体部分赋值问题
- 关于结构体数组的赋值问题
- c语言实现读取txt文件内容到结构体数组中
- PHP 读取与写入txt文件并并赋值给数组
- PHP读取txt文件的内容并赋值给数组…
- java解析txt文件
- ASP.NET页面指令
- matlab读取txt,excel文件数据,图中图,局部放大
- 使用Python编写的文件备份程序
- JVM内存模型
- Odyssey会议文章
- 解析txt文件,赋值结构体数组
- The 2008 NIST Speaker Recognition Evaluation
- 声纹识别参考文献
- java类加载及new对象的过程
- Gradle3.3 Re_download deppendencies and sync project(requires network)
- Linux和Windows符号导入导出的对比分析
- python开发环境搭建
- 腾讯声纹识别研究
- includeOS的学习笔记