c++ - 在 qt 中用 C++ 创建 .csv 文件

标签 c++ qt qt4 export-to-csv qtcore

我想使用 C++ 创建一个 csv 文件,将 Qt 用于应用程序和 UI 框架。是否有用于 csv 文件的库。

最佳答案

尝试 qtcsv用于读取和写入 csv 文件的库。示例:

#include <QList>
#include <QStringList>
#include <QDir>
#include <QDebug>

#include "qtcsv/stringdata.h"
#include "qtcsv/reader.h"
#include "qtcsv/writer.h"

int main()
{
    // prepare data that you want to save to csv-file
    QStringList strList;
    strList << "one" << "two" << "three";

    QtCSV::StringData strData;
    strData.addRow(strList);
    strData.addEmptyRow();
    strData << strList << "this is the last row";

    // write to file
    QString filePath = QDir::currentPath() + "/test.csv";
    QtCSV::Writer::write(filePath, strData);

    // read data from file
    QList<QStringList> readData = QtCSV::Reader::readToList(filePath);
    for ( int i = 0; i < readData.size(); ++i )
    {
        qDebug() << readData.at(i).join(",");
    }

    return 0;
}

我试图让它变得小巧易用。参见 Readme库文档和其他代码示例的文件。

关于c++ - 在 qt 中用 C++ 创建 .csv 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22802491/

相关文章:

c++ - LNK2019带模板

qt - QObjectList 和 QList 的区别

c++ - Qt4.8 : Why enum not seen in qmetaobject? 以及如何工作?

python - 如何在qt4的文本编辑框中创建多个选择?

c++ - Qt 中的智能指针内存管理器

c++ - 在 QGraphicsScene 中使用自定义坐标

c++ - 使用模板

c++ - 如何从 C++ 程序中打开自定义 I/O 流?

c++ - 生成运行时递归调用树的工具

c++ - CheckRemoteDebuggerPresent 在 MingW 中不存在