16,472
社区成员
发帖
与我相关
我的任务
分享
try
{
CFile file(_T("F:\\11.txt"), CFile::modeCreate | CFile::modeWrite);
#define MAX_ROW 2
#define MAX_COL 3
float YK[MAX_ROW][MAX_COL] = {0};
YK[0][0]=0.0f;
YK[0][1]=0.1f;
YK[0][2]=0.2f;
YK[1][0]=1.0f;
YK[1][1]=1.1f;
YK[1][2]=2.2f;
char buf[64] = {0};
for(int i=0; i<MAX_ROW; i++)
{
sprintf(buf, "%.1f, %.1f, %.1f\r\n", YK[i][0], YK[i][1], YK[i][2]);
file.Write(buf, strlen(buf) * sizeof(char));
}
file.Close();
}
catch (CFileException* e)
{
e->ReportError();
e->Delete();
}
//---------------------------------------------------------------------------
#include <iostream>
#include <fstream>
#define N 2//数据的行数
using std::ofstream;
using std::endl;
int main(void)
{
double YK[N][3];
ofstream ofs("c:\\a.txt");//将数据写入c:\a.txt文件
YK[0][0]=0.0;
YK[0][1]=0.1;
YK[0][2]=0.2;
YK[1][0]=1.0;
YK[1][1]=1.1;
YK[1][2]=2.2;
for (int i=0; i<N; i++) { //写入数据
for (int j=0; j<3; j++) {
ofs<<YK[i][j];
if (j<2) ofs<<",";
}
ofs<<endl;
}
ofs.close(); //关闭文件
return 0;
}
//---------------------------------------------------------------------------