C++ File I/O 的問題

2007-03-13 8:17 am
#include
#include
#include
#include
using namespace std;
int main ()
{
time_t rawtime;
struct tm * timeinfo;

time ( &rawtime );
timeinfo = localtime ( &rawtime );
printf ( "Current local time and date: %s", asctime (timeinfo) );
更新1:

ofstream fout("myfile.cpp"); fout

更新2:

fout << "This line is written to file.\n";<----------想f output 個time 入去個file

更新3:

fout.close(); ifstream fin("myfile.cpp");

更新4:

char ch; while (fin.get(ch)) //false if EOF is got

更新5:

cout

更新6:

return 0; }

更新7:

show 唔到我 #include stdio.h , time.h, #include ,

更新8:

其實我問題係我想 output 個時間入去個 file output 度... 但係我唔知道要 put 那一個 入去 fou<<果度, ths!

更新9:

得咗了.. 多謝你!!!!

回答 (1)

2007-03-13 4:42 pm
✔ 最佳答案
如閣下只須把asctime寫到你的輸出檔案的話,
可以試一下以下的一句:
fout &lt;&lt; &quot;This line is written to file.&quot; &lt;&lt; endl &lt;&lt; asctime(timeinfo) &lt;&lt; endl;


收錄日期: 2021-04-30 00:08:05
原文連結 [永久失效]:
http://hk.knowledge.yahoo.com/question/question?qid=7007031300070

檢視 Wayback Machine 備份