C++写csv文件
其中有一个点需要注意,csv芬里尔之间要用逗号隔开
p_str_filename ="D:\\1.csv";
int writelog(string p_str_filename, double p_double[])
{SYSTEMTIME timeCur;GetLocalTime(&timeCur);char t_logbuffer[1024] = { 0 };sprintf(t_logbuffer, ("%04d%02d%02d_%02d:%02d:%02d:%03d,"), timeCur.wYear, timeCur.wMonth, timeCur.wDay, timeCur.wHour, timeCur.wMinute, timeCur.wSecond, timeCur.wMilliseconds);char tep[1024] = { 0 };sprintf(tep, ("%02f,%02f,%02f,%02f,%02f\n"), p_double[0], p_double[1], p_double[2], p_double[3], p_double[4]);strcat(t_logbuffer, tep);t_logbuffer[1024 - 1] = '\0';FILE* FP = fopen(p_str_filename.c_str(), "a+");if (FP == NULL){return -1;}fwrite(t_logbuffer, 1, strlen(t_logbuffer), FP);fclose(FP);return 0;
}