Sign in to follow this  
TylerMoore

Include & Ostream issue

Recommended Posts

I'm using Visual Studio 2008, and working off an old project originally written/compiled in Visual Studio 6.0 Currently, this code is giving me problems:
//headerfile.h

#include <fstream>

class CTrace
{
  /* unrelated class code */
  void dump_to_file(ofstream *pout_stream);
};

template <class T> class Trace_Array
{
  T *m_parray;
  DWORD m_array_size;
  DWORD m_index;
  ofstream m_fout;
public:
  ofstream *get_fstream(void){return &m_fout;}
  DWORD get_size(void){return m_array_size;}
  void reset(DWORD new_index){m_index = (new_index % m_array_size);}
  Trace_Array(DWORD size, char *fname)
  {
    m_parray = new T[size];
    m_array_size = size;
    m_fout.open(fname);
    m_index = 0;
  }
  virtual ~Trace_Array(void)
  {
    if(m_fout.is_open())
      m_fout.close();
    
    if(m_parray)
    {
      delete [] m_parray;
      m_parray = NULL;
    }
  }

  T *operator++(int)
  {
    T *curobj;
    if(m_parray)
    {
      curobj = &m_parray[m_index];
      m_index++;
      m_index %= m_array_size;
      return curobj;
    }
    return NULL;
  }
};

I am getting errors like these (in general, it has a problem with "ofstream"): error C2143: syntax error : missing ';' before '*' error C4430: missing type specifier - int assumed. Note: C++ does not support default-int I'm pretty sure it has something to do with the include files I'm using. I changed the original set of includes from: #include <fstream.h> //to #include <fstream> I also tried using #include <ofstream> to no avail. Any help?, also, how do you add code tags so it's formatted nicely? [Edited by - TylerMoore on June 1, 2009 12:37:16 PM]

Share this post


Link to post
Share on other sites
You can use [code] or [source] to format code. As for your compiler errors, it seems that you need to account for the fact that ofstream and related classes live in the std namespace. So you'd use std::ofstream, etc.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this