1.c写文件
FILE *fopen( const char * filename, const char * mode );
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
int main()
{
FILE* fp = NULL;
fp = fopen("test.txt", "w+");
fprintf(fp, "This is testing for fprintf...\n");
fputs("This is testing for fputs...\n", fp);
fclose(fp);
return 0;
}
//所写字符需要转为char型字符串
2.c++写文件
#include <fstream>
#include <iostream>
#include<string>
using namespace std;
std::ofstream OsWrite("testcpp.txt", std::ofstream::app);
std::string clsname = objects[i].class_name;
OsWrite << clsname << ",";
OsWrite << std::to_string(objects[i].x) << ",";
OsWrite << std::to_string(objects[i].y) << ",";
OsWrite << std::to_string(objects[i].w) << ",";
OsWrite << std::to_string(objects[i].h) << ",";
OsWrite << std::to_string(objects[i].score) << "," << "\n";
OsWrite << std::endl;
OsWrite.close();