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,
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,