老板写的,很好用。
#include <time.h>
void ourAlgae::CreateDIR(string& _path)
{
if( (_path=="") || _path.empty())
{
return;
}
path m_Path(_path);
if(!exists(m_Path))
{
create_directories(m_Path);
}
}
int ourAlgae::SaveReult(math_calc_result_t& _result,const char*_filepath)
{
const char algaestatic[40][100]={"0马齿苋","1马蹄莲","2粉玫瑰","3小雏菊","4百合","5向日葵"...};
if(_filepath==NULL)
{
return -2;
}
time_t timenow;
struct tm *sTime;
timenow = time(NULL);
sTime = localtime( &timenow);
ostringstream file_ostr;
file_ostr<<sTime->tm_year+1900<<"-"<<sTime->tm_mon+1<<"-"<<sTime->tm_mday<<' '<<sTime->tm_hour<<':'<<sTime->tm_min<<':'<<sTime->tm_sec<<".data";
string filestr(_filepath);
CreateDIR(filestr);
filestr+=('/'+file_ostr.str());
FILE *fp_r=NULL;
fp_r = fopen(filestr.c_str() , "w+");
if(fp_r!=NULL){
char context[100]={0};
for(int i=0;i<40;i++)
{
if(_result._alage_count[i]>0)
{
memset(context,0,sizeof(context));
sprintf(context,"%s,%u个\n",algaestatic[_result._alage_names[i]],_result._alage_count[i]);
fwrite(context, sizeof(char), strlen(context), fp_r);
}
}
fclose(fp_r);
}
return 0;
}
多维动态数组的创建与释放:
/* //三维动态矩阵 多维动态矩阵应从外向里创建 从里向外释放
uchar*** arr_np3D = NULL;
arr_np3D = (uchar***)new uchar**[256];
for (int i = 0; i<256; i++)
{
arr_np3D[i] = (uchar**)new uchar*[256];
}
for (int i = 0; i<256; i++)
{
for (int j = 0; j<256; j++)
{
arr_np3D[i][j] = new uchar[256];
}
}
释放:
//delete[] rgbarray; //一维动态数组这样释放
/*多维动态数组是这样释放的
for (int i = 0; i<256; i++)
{
for (int j = 0; j<256; j++)
{
delete[] arr_np3D[i][j];
}
}
delete[] arr_np3D;
*/