every blog every motto: You will never know unless you try
0. 前言
C++将数组写入CSV文件,简单记录
1. 正文
#include<iostream>
using namespace std;
#include<fstream>
void test666()
{
cout << "我是测试程序:" << endl;
int arr[3][5] = {
{
1,0,1,0,1 },
{
1,1,1,0,1 },
{
0,0,0,0,1 }
};
int all = sizeof(arr)/sizeof(int);
cout << "数组元素总数为:"<<all << endl;
int column = sizeof(arr[0]) / sizeof(arr[0][0]);
int row = all / column;
cout << "数组的行:" << row << endl;
cout << "数组的列:" << column << endl;
ofstream outFile; // 创建流对象
outFile.open("test.csv", ios::out); // 打开文件
for (int i = 0; i < row; i++)
{
for (int j = 0; j < column; j++)
{
outFile << arr[i][j]<<',' ;
}
outFile << endl;
}
outFile.close(); // 关闭文件
}
参考文献
[1] https://blog.csdn.net/weixin_39190382/article/details/108242125
[2] https://blog.csdn.net/sinat_38792591/article/details/100190990?utm_medium=distribute.pc_relevant.none-task-blog-title-1&spm=1001.2101.3001.4242