Qt语言如何读取CSV文件
来源:互联网 发布:李善姬在韩国地位知乎 编辑:程序博客网 时间:2024/05/08 12:49
/*************存储数据**************/
QList<QString> stringList;
QVector<QVector<QString>> dataVector;
QString str;
int const rowCount = 361;
int const columnCount = 949;
//double* dataArray = new double[rowCount*columnCount];
QFile file("china_sites_20140513.csv");
if (file.open(QIODevice::ReadOnly))
{
while (!file.atEnd())
{
qint64 lineLen; //用于按行读取数据
char buffer[5800];//存储每行的字符串
lineLen = file.readLine(buffer, sizeof(buffer));
if (lineLen != -1)//如果读取成功
{
str = buffer;
stringList = str.split("\r", QString::SkipEmptyParts);//按换行分割
str = stringList[0];
stringList = str.split("\n", QString::SkipEmptyParts);//按回车键分割
str = stringList[0];
stringList = str.split(",", QString::SkipEmptyParts);//按逗号分割
QListIterator<QString> li(stringList);
int i = 0;
QVector<QString> temp_dataList(i, 0);
for (; li.hasNext();)
{
//double temp;
QString temp;
//temp = li.next().toDouble();//把字符串转换成double型数据
temp = li.next();
temp_dataList.push_back(temp);
i++;
}
dataVector.push_back(temp_dataList);
}
}
}
//测试:
for (int i = 0; i < dataVector.size(); i++)//dataVector.size()=向量的行数
{
for (int j = 0; j < columnCount; j++)
{
if (j != columnCount - 1)
{
QByteArray ba=dataVector[i][j].toLocal8Bit();//toLocal8Bit()返回一个QByteArray类型
cout << ba.data();//data()返回char *
//其它类型变量还是可以照常输出的。
printf(",");
}
else
{
QByteArray ba = dataVector[i][j].toLocal8Bit();//toAscii()返回一个QByteArray类型
std::cout << ba.data();//data()返回char *
printf("%\n");
}
}
//cout << endl;
}
QList<QString> stringList;
QVector<QVector<QString>> dataVector;
QString str;
int const rowCount = 361;
int const columnCount = 949;
//double* dataArray = new double[rowCount*columnCount];
QFile file("china_sites_20140513.csv");
if (file.open(QIODevice::ReadOnly))
{
while (!file.atEnd())
{
qint64 lineLen; //用于按行读取数据
char buffer[5800];//存储每行的字符串
lineLen = file.readLine(buffer, sizeof(buffer));
if (lineLen != -1)//如果读取成功
{
str = buffer;
stringList = str.split("\r", QString::SkipEmptyParts);//按换行分割
str = stringList[0];
stringList = str.split("\n", QString::SkipEmptyParts);//按回车键分割
str = stringList[0];
stringList = str.split(",", QString::SkipEmptyParts);//按逗号分割
QListIterator<QString> li(stringList);
int i = 0;
QVector<QString> temp_dataList(i, 0);
for (; li.hasNext();)
{
//double temp;
QString temp;
//temp = li.next().toDouble();//把字符串转换成double型数据
temp = li.next();
temp_dataList.push_back(temp);
i++;
}
dataVector.push_back(temp_dataList);
}
}
}
//测试:
for (int i = 0; i < dataVector.size(); i++)//dataVector.size()=向量的行数
{
for (int j = 0; j < columnCount; j++)
{
if (j != columnCount - 1)
{
QByteArray ba=dataVector[i][j].toLocal8Bit();//toLocal8Bit()返回一个QByteArray类型
cout << ba.data();//data()返回char *
//其它类型变量还是可以照常输出的。
printf(",");
}
else
{
QByteArray ba = dataVector[i][j].toLocal8Bit();//toAscii()返回一个QByteArray类型
std::cout << ba.data();//data()返回char *
printf("%\n");
}
}
//cout << endl;
}
0 0
- Qt语言如何读取CSV文件
- QT 读取csv文件
- 如何读取csv文件
- C语言读取CSV文件
- R语言读取csv文件
- C语言读取csv文件
- Qt 从csv文件中读取数据
- R语言读取csv文件出错
- 如何读取csv文件的内容
- 如何读取csv文件并存入数据库?
- Python中如何读取CSV文件
- Matlab:如何读取CSV文件以及如何读取带有字符串数据项的CSV文件
- C语言读取CSV文件的方法1
- C语言读取CSV文件的方法2
- R语言 : 读取csv 文件, 画基金净值线
- CSV文件直接读取
- C#读取CSV文件
- java读取CSV文件
- a+b 高精度
- 使用版本控制工具SVN的项目中各种小图标所代表的具体含义
- APACHE内外网链接
- Java枚举类型详解(原理+用法)
- 9.python数据结构-列表-建立/索引/反转
- Qt语言如何读取CSV文件
- struts2 国际化 I18N
- KD-Tree
- raid5记录
- html5 input file 打开过慢
- Android权限机制与适配经验
- Android多屏幕适配-平板
- android 状态栏操作之-改变状态栏的颜色
- Python 元组