|
-
February 1st, 2001, 08:04 PM
#1
problem with ofstream
I have got a strange problem.I have the following code:
I have a static method in X.cpp which is as follows:
void X::log() {
if(fs.is_open() == 0) {
fs.open("log.txt",ios::app);
fs<<"hello";
} else
fs<<"hello";
}
}
I declare the fs(ofstream) as static in the following way in X.cpp:
ofstream X::fs;
Now I call this method 100 times from Y.cpp in the following fashion:
#include "X.cpp"
void main() {
for(int i=0;i<100;i++) {
X::log();
}
}
As the ofstream object fs is a static variable it should open log.txt for the first time and should
always point to log.txt. But it is writing to the file log.txt only once. What can be the reason?
Thanx in Advance,
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|