Include & Ostream issue

Started by
1 comment, last by TylerMoore 14 years, 10 months ago
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]
Advertisement
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.
That did it, thank you!

This topic is closed to new replies.

Advertisement