如何在VC ++中将数据记录到文件中? [英] How to log data to a file in VC++?

查看:202
本文介绍了如何在VC ++中将数据记录到文件中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要将数据记录到文件(filename.log)。文件大小达到1 MB后,数据应移动到另一个文件(例如filename_1.log),新数据应记录到filename.log。这应该以循环格式发生。最大文件数5.



需要帮助。



提前致谢

I need log the data to a file (filename.log). After the file size reaches 1 MB, the data should be moved to another file (say filename_1.log) and the new data should be logged to "filename.log". This should happen in a circular format. Maximum number of files 5.

Need Help.

Thanks in advance

推荐答案

hi,

这个链接有一些很好的代码..请参阅dr.dobbs链接为了更好地理解 [ ^ ]

a好方法是创建一个单独的类来记录CLogger并在整个项目中使用它。创建clogger.h并将所有相关函数的声明放入其中,例如将现有文件'curentlog.log'重命名为'oldlog1.log'(当它超过1 mb时),以及日期和时间函数等。然后实现这些函数相应的.cpp文件。

首先创建一个日志文件,然后查看是否能够将信息写入其中。然后继续前进。

记住'谷歌'是你最好的朋友,你需要的一切。

这也是了解单独模式的工作原理 [ ^ ]

this link has some good code .. see the dr.dobbs links for better understanding[^]
a good approach would be to create a separate class for logging say CLogger and use it through out the project. Make clogger.h and put in it all the relevant function's declarations for example the renaming of existing file 'curentlog.log' to 'oldlog1.log' when it crosses 1 mb, and the date and time functions etc. Then implement these functions in the respective .cpp file.
start by creating a single log file and see if you are able to get info written to it. Then proceed ahead.
Remember 'Google' is your best friend for everything you need .
This is also a good way to see how singleton pattern works[^]


这篇关于如何在VC ++中将数据记录到文件中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆