[LC++]problem related to traits
choube mehul
choube_mehul at yahoo.com
Thu May 5 19:17:02 UTC 2005
Hi,
i am getting lots of error for the following
code.
i am newbie to traits.
any help will be great.
Thanks,
Mehul.
/************ Code Start **************/
#include <fstream>
#include <streambuf>
#pragma warning (pop)
template <class charT, class
traits=std::char_traits<charT> >
class debugstreambuf : public
std::basic_streambuf<charT, traits>
{
public:
typedef charT char_type;
typedef std::basic_string<char_type, traits>
LocalString;
explicit debugstreambuf(void)
{
}
~debugstreambuf()
{
}
void SetOutputTargetFileName(const LocalString&
fileName)
{
if (!fileName.empty())
{
m_LogFileName=fileName;
}
}
protected:
virtual std::streamsize xsputn(const char_type* s,
std::streamsize nHowmany)
{
CSigGateKeeper myGuard(m_csWriteOutputLock);
if (m_LogFile.is_open() == false)
{
CreateLogFile();
}
if (m_LogFile.good())
{
m_LogFile << s;
}
#if defined(_DEBUG) && defined(_WIN32)
OutputDebugStringA(s);
#endif
return (nHowmany);
}
virtual int_type overflow(int_type c=traits::eof())
{
// this method is supposed to flush the put area
of the buffer
// to the I/O device
if (m_LogFile.is_open() == false)
{
CreateLogFile();
}
if (m_LogFile.good())
{
m_LogFile << (char_type)c;
}
#if defined(_WIN32) && defined(_DEBUG)
TCHAR achOutput[2];
achOutput[0]=static_cast<TCHAR>(c);
achOutput[1]='\0';
OutputDebugString(achOutput);
#endif
return (1);
}
int sync(void)
{
m_LogFile.flush();
return 0;
}
virtual void CreateLogFile(void)
{
if (m_LogFileName.empty() == false)
{
m_LogFile.open(m_LogFileName.c_str(),
std::ios_base::out | std::ios_base::app);
}
}
private:
// not for use
debugstreambuf(const debugstreambuf&);
debugstreambuf& operator=(const debugstreambuf&);
LocalString m_LogFileName;
std::basic_ofstream<char_type,traits> m_LogFile;
};
/************ Code End **************/
/************ Error Start **************/
s:\SigFCL_\v2.7.2.0\include\debugstreambuf.h(61) :
error C2146: syntax error : missing ';' before
identifier 'char_type'
s:\SigFCL_\v2.7.2.0\include\debugstreambuf.h(61) :
error C2868:
'std::basic_streambuf<_Elem,_Traits>::char_type' :
illegal syntax for using-declaration; expected
qualified-name
with
[
_Elem=char,
_Traits=std::char_traits<char>
]
s:\SigFCL_\v2.7.2.0\include\debugstreambuf.h(62) :
error C2065: 'traits' : undeclared identifier
s:\SigFCL_\v2.7.2.0\include\debugstreambuf.h(62) :
error C2955: 'std::basic_string' : use of class
template requires template argument list
c:\Program Files\Microsoft Visual Studio .NET
2003\Vc7\include\xstring(1542) : see declaration of
'std::basic_string'
s:\SigFCL_\v2.7.2.0\include\debugstreambuf.h(62) :
error C2955: 'std::basic_string' : use of class
template requires template argument list
c:\Program Files\Microsoft Visual Studio .NET
2003\Vc7\include\xstring(1542) : see declaration of
'std::basic_string'
s:\SigFCL_\v2.7.2.0\include\debugstreambuf.h(181) :
error C3861: 'traits': identifier not found, even with
argument-dependent lookup
s:\SigFCL_\v2.7.2.0\include\debugstreambuf.h(181) :
error C2955: 'std::basic_ofstream' : use of class
template requires template argument list
c:\Program Files\Microsoft Visual Studio .NET
2003\Vc7\include\iosfwd(454) : see declaration of
'std::basic_ofstream'
s:\SigFCL_\v2.7.2.0\include\debugstreambuf.h(181) :
error C2955: 'std::basic_ofstream' : use of class
template requires template argument list
c:\Program Files\Microsoft Visual Studio .NET
2003\Vc7\include\iosfwd(454) : see declaration of
'std::basic_ofstream'
s:\SigFCL_\v2.7.2.0\include\debugstreambuf.h(181) :
error C2079:
'SigFoundation::debugstreambuf::m_LogFile' uses
undefined class 'std::basic_ofstream'
s:\SigFCL_\v2.7.2.0\source\datatypes\path\path.cpp(841)
: fatal error C1903: unable to recover from previous
error(s); stopping compilation
/************ Error End **************/
________________________________________________________________________
Yahoo! India Matrimony: Find your life partner online
Go to: http://yahoo.shaadi.com/india-matrimony
More information about the tuxCPProgramming
mailing list