struct GPattern() {
int gid;
....
}
class Example() {
public:
void run(string _filename, unsigned int _minsup);
void PrintGPattern(GPattern&, unsigned int sup);
....
};
Eample::run(string filename, unsigned int minsup) {
for(...) { // some condition
// generate one GPattern, and i want to ouput it
PrintGPattern(gp, sup);
}
}
Example::PrintGPattern(GPattern& gp, unsigned int sup) {
// I want to ouput each GPattern to a .txt file
}
run is used to generate a GPattern accordingly.
What I want to output to a file is some texts that reconstruct the original GPattern.
I can’t store all GPattern in advance and output all of them. I have to output one GPattern to a file when I generate it, but I don’t know how to implement it.
I have tried to declare ofstream outGPatter("pattern.txt") in class Example, but it is of no use…
Well, ofstream is the right way to go:
Have you looked at the correct place for the pattern.txt? It should either be in the folder where your .exe is, or in the folder where all your .h and .cpp files are (for VS at least).
If you want to write all patterns into the same file then you need to make sure you append (and not overwrite) the pattern.txt
So you can first make an ofstream without ios::app (to clear the textfile) at the start of your program. Then you construct all other ofstreams with ios::app to append new text, instead of overwriting it.
Alternatively you can make the ofstream a member variable of Example. Then you construct it only once.