现在越来越感觉到我们做图象算法的,写好通用的c才是王道。记录下些平时的技巧,大家探讨
1. 得到文件长度
long fgetlength(char *sfile)
{
if(sfile==NULL || _access(sfile,0)!=0 ) return 0;
FILE *pf =fopen(sfile,"r+b"); if(pf==NULL) return 0;
long length = 0;
fseek(pf,SEEK_END);
length = ftell(pf);
fclose(pf);
return pf;
}
2. 历遍文件 (zz from honker110(honker))
#include <string>
#include <vector>
#include <map>
#include <iostream>
#include <fstream>
#include <io.h>
main()
{
std::string str = "<html><head><title>ISAPI Upload Demo</title></head><body>";
struct _finddata_t c_file;
long hFile;
/* Find first .c file in current directory */
if((hFile = _findfirst("*.*", &c_file)) == -1L)
printf("No files in directory!/n");
else
{
str += c_file.name;
str += "<br/>";
/* Find the rest of the .c files */
while( _findnext( hFile, &c_file ) == 0 )
{
str += c_file.name;
str += "<br/>";
}
_findclose( hFile );
}
str += "</body></html>";
printf(str.c_str());
}