#include "stdafx.h"
#include<vector>
#include<string>
#include<fstream>
#include<iostream>
#include<sstream>
using namespace std;
int _tmain(int argc, _TCHAR* argv[])
{
ofstream outFile;
outFile.open("D:\\myfile.csv",ios::in);
if(!outFile){
outFile.open("D:\\myfile.csv",ios::out);
outFile << "Name" << "," << "age" << "," << "height" << endl;
outFile.close();
}
else{
outFile.close();
outFile.open("D:\\myfile.csv",ios::out|ios::ate|ios::app);
outFile << "Tom" << "," << 21 << "," << 172.8 << endl;
outFile << "John" << "," << 25 << "," << 189.5 << endl;
outFile.close();
}
return 0;
}
檔案不存在時,if執行,檔案創建成功,但不會寫入資料
各位大佬幫忙看一下哪個地方出了問題,謝謝了
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/273827.html
標籤:C++ 語言
上一篇:第一行C語言代碼,最大值,求和
