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 7129499
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T11:14:57+00:00 2026-05-28T11:14:57+00:00

I am trying to make a pointer to fstream so I can use it

  • 0

I am trying to make a pointer to fstream so I can use it in all of my class methods :

class P
{
    private:
        fstream *fs;

    public:
        P()
        {
            fstream fs(filepath, openmode);
            this->fs = &fs;
        }
};

But it seem to be not pointing to it at all e.g if I write:

fs->is_open() 

it will return false, whereas if I write:

fs.is_open()

it will return true.

What is causing this? I also tried to change the pointer to another like fstr but that didn’t work either.

  • 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-05-28T11:14:57+00:00Added an answer on May 28, 2026 at 11:14 am

    To accomplish what you are asking for, you need to use the new operator, like this:

    SmartIO::SmartIO(const char * filepath , Mode mode)
        : fs(NULL), buffer(NULL), offset(0)
    {
        switch (mode)
        {
            case Mode::inText:
            {
                fs = new fstream(filepath,fstream::in|fstream::ate);
                break;
            }
            case Mode::inBinary:
            {
                fs = new fstream(filepath,fstream::in|fstream::binary|fstream::ate);
                break;
            }
        }
    
        if ((fs) && (fs->is_open()))
        {
            buffer = new std:vector<char>(fs->tellg(), 0);
            fs->seekg(0, ios::beg);
            fs->read(buffer->data(), buffer->size());
        }
        else
        {
            printf( "cant open the file!");
        }
    }
    
    SmartIO::~SmartIO()
    {
        delete fs;
        delete buffer;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to make a button class (abstract) so I can set what function
Trying to make a make generic select control that I can dynamically add elements
I have been trying to make a StringTable class that holds a simple unordered_map<string,
I am trying to make an app which use displacement map for 3d effect.
I'm trying to make a macro in C that can tell if a char
I'm trying to make a pointer point to a 2D array of pointers. What
I am currently trying to make an existing VB.NET Project run. A null pointer
I'm trying to make a simple logger class, and I want the ability to
I'm trying to make a function that takes a character, then returns a pointer
I am trying to make a class that contains two other objects, and those

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.