Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7742849
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T09:22:53+00:00 2026-06-01T09:22:53+00:00

struct GPattern() { int gid; …. } class Example() { public: void run(string _filename,

  • 0
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…

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T09:22:55+00:00Added an answer on June 1, 2026 at 9:22 am

    Well, ofstream is the right way to go:

    Example::PrintGPattern(GPattern& gp, unsigned int sup) {
        ofstream outGPattern("pattern.txt")
    
        outGPattern << gp.gid; << " " << gp.anotherGid << " " ....
    
        outGPattern.close()
    }
    

    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

    ofstream outGPattern(“pattern.txt”,ios::app)

    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.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

struct Div { int i; int j; }; class A { public: A(); Div&
struct Drink { public string Name { get; private set; } public int Popularity
struct SomeStruct { public int Num { get; set; } } class Program {
struct ID3v2_header{ char tag[3]; char ver[2]; char flag; int size; }; ID3v2_header readID3v2_head(string file){
struct A { template <class U> void f(U) { } }; template <class T>
struct T { void eat(std::string const& segment) { buffer << segment; std::string sentence; while
struct person { int age; char name[100]; struct person *next; }; void delfirst(struct person
struct DummyStruct{ unsigned long long std; int type; }; DummyStruct d; d.std = 100;
struct a { public int x; } struct c { public byte x; }
struct TimerEvent { event Event; timeval TimeOut; static void HandleTimer(int Fd, short Event, void

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.