vc中如何使用文件?? win32里好像不能用mfc的类吧? 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 你的工程不支持MFC,所以不能用cfile!在project--setting里改 我的意思是不使用project--setting的use in mfc CCriticalSection log_lock; //全局变量bool LOG_ERR(char *log_buffer){ FILE *fp; char tmpbuf[1024],cc[10],filename[100]; struct tm *newtime; time_t long_time; time( &long_time ); /* Get time as long integer. */ newtime = localtime( &long_time ); /* Convert to local time. */ sprintf(filename, ".\\log\\%d-%d-%d_err.txt",(newtime->tm_year + 1900),(newtime->tm_mon + 1),newtime->tm_mday ); //下面的操作需要加锁 log_lock.Lock(); if ( ( fp = fopen(filename,"a+") ) == NULL ) { if ( ( fp = fopen(filename,"w+") ) == NULL ) { printf("error open log file"); return -1; } } /* Write Message To The End Of Trace File */ _strtime(cc); sprintf(tmpbuf,"%s--%s\n", cc, buf ); fputs( tmpbuf, fp); /* close trace file */ fclose( fp ); log_lok.Unlock(); //完成之后将锁释放掉} 还是直接用mfc中的文件比较方便,加入mfc的支持,如果代码不太多最好重新做一个,有“应用程序向导”,比较安全,如果你对手动添加mfc不太熟! 用下面几个Function了,具体请查阅MSDNHANDLE hFile = CreateFile(...);BOOL bRead = ReadFile(hFile,...);BOOL bWrite = WriteFile(hFile,...);CloseHandle(hFile); 这么麻烦吗,算了,结贴,给分,还是用MFC算了, API报错,求解决方案 第一次发帖,望大侠指点! 浮点型转化为字符型 ODBC 访问access问题!请高手帮忙 如何快速进行数组之间的赋值移动?? 一个礼拜没搞定只好想这么一个办法求源代码:mfc主程序起来后要求用creatprocess调notepad程序,然后锁住系统的键盘和鼠标,其间可以按下 送分讨论*.c到*.cpp在vc++中编译时应该注意哪些问题! (1000分奉上)谁懂 Bridge的telerate?? 请教如何在系统的进程表中,将某一进程隐藏? 微软MCSD认证对编程技术的提高有多大帮助,难度如何?“钱”途如何? 各位高手请多多指点 各位高手和老手请进!!!
bool LOG_ERR(char *log_buffer)
{
FILE *fp;
char tmpbuf[1024],cc[10],filename[100];
struct tm *newtime;
time_t long_time;
time( &long_time ); /* Get time as long integer. */
newtime = localtime( &long_time ); /* Convert to local time. */ sprintf(filename, ".\\log\\%d-%d-%d_err.txt",(newtime->tm_year + 1900),(newtime->tm_mon + 1),newtime->tm_mday ); //下面的操作需要加锁
log_lock.Lock(); if ( ( fp = fopen(filename,"a+") ) == NULL )
{
if ( ( fp = fopen(filename,"w+") ) == NULL )
{
printf("error open log file");
return -1;
}
}
/* Write Message To The End Of Trace File */
_strtime(cc);
sprintf(tmpbuf,"%s--%s\n", cc, buf );
fputs( tmpbuf, fp);
/* close trace file */
fclose( fp ); log_lok.Unlock();
//完成之后将锁释放掉
}
HANDLE hFile = CreateFile(...);
BOOL bRead = ReadFile(hFile,...);
BOOL bWrite = WriteFile(hFile,...);
CloseHandle(hFile);