1、输出字符到CSV到文件
oFile << “姓名” << “,” << “年龄” << “,” << “班级” << “,” << “班主任” << endl;
上述代码将 “姓名”这些字符串直接写入打开或新建的文件中
2、输出变量到CSV到文件
oFile << to_string (a) << “,” << to_string (b) << “,” <<to_string © << “,” << “JIM” << endl;
只需要将变量的内容转换成string格式即可
3、Qdebug()
qDebug("%02x %02x",a,b);
这里的qebug()的用法和printf()用法一致
程序源码如下
#include “mainwindow.h”
#include “ui_mainwindow.h”
#include
#include
#include
using namespace std;
static char a=6,b=5,c=4;
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
//定义文件输出流
ofstream oFile;
//打开要输出的文件
oFile.open("222.csv", ios::out | ios::trunc);
oFile << "姓名" << "," << "年龄" << "," << "班级" << "," << "班主任" << endl;
for(int i=0;i<15;i++){
oFile << to_string (a) << "," << to_string (b) << "," <<to_string (c) << "," << "JIM" << endl;
qDebug("%02x %02x",a,b);
}
oFile.close();
}
MainWindow::~MainWindow()
{
delete ui;
}
上述程序输出结果如下