VC++ 2005 - Compilation Errors using "ifstream"

I am attempting to compile a project in Visual Studio 2005 which compiles 
and links properly in VC++ 6.0.  It seems to have problems with C++ i/o 
functions.  Here is the error I get:

g:\src\analyzer\digitdialpages.h(136) : error C2146: syntax error : missing 
';' before identifier 'm_InFile'
Line 136:    ifstream m_InFile;

The statment:  include <fstream> is at the top of the source file.

Some assistance would be helpful.  We didn't have any problems with using 
ifstream or ofstream in VC++ 6.0.  Thanks.




0
rajk2000 (39)
12/12/2006 11:22:47 PM
vc.mfc 33608 articles. 0 followers. Follow

3 Replies
745 Views

Similar Articles

[PageSpeed] 21

On Tue, 12 Dec 2006 18:22:47 -0500, "Raj Kulkarni"
<rajk2000@msn.com.invalid> wrote:

>I am attempting to compile a project in Visual Studio 2005 which compiles 
>and links properly in VC++ 6.0.  It seems to have problems with C++ i/o 
>functions.  Here is the error I get:
>
>g:\src\analyzer\digitdialpages.h(136) : error C2146: syntax error : missing 
>';' before identifier 'm_InFile'
>Line 136:    ifstream m_InFile;
>
>The statment:  include <fstream> is at the top of the source file.
>
>Some assistance would be helpful.  We didn't have any problems with using 
>ifstream or ofstream in VC++ 6.0.  Thanks.

Use std::ifstream, and read up on namespaces. See also:

How to: Upgrade Projects from Previous Versions of Visual C++  
http://msdn2.microsoft.com/en-us/library/kyb7zzw4(VS.80).aspx

VC6 -> VC2005 is a big jump. The old <iostream.h> headers have gone away,
and you may have some issues moving to the standard <iostream> family.

-- 
Doug Harrison
Visual C++ MVP
0
dsh (2498)
12/12/2006 11:41:26 PM
I tried your advice, and replaced "ifstream" with "std::ifstream".  I also 
replaced instances of "ofstream" with "std::ofstream".  Those syntax errors 
were resolved.
When I added "std" to the following statement:  m_InFile.open(m_sFileName, 
ios::in | ios::binary);
which became
    m_InFile.open(m_sFileName, std::ios::in | std::ios::binary);

I get the following errors:

g:\program files\microsoft visual studio 8\vc\include\fstream(675) : error 
C2248: 'std::basic_ios<_Elem,_Traits>::basic_ios' : cannot access private 
member declared in class 'std::basic_ios<_Elem,_Traits>'
        with
        [
            _Elem=char,
            _Traits=std::char_traits<char>
        ]
        g:\program files\microsoft visual studio 8\vc\include\ios(151) : see 
declaration of 'std::basic_ios<_Elem,_Traits>::basic_ios'
        with
        [
            _Elem=char,
            _Traits=std::char_traits<char>
        ]
        This diagnostic occurred in the compiler generated function 
'std::basic_ifstream<_Elem,_Traits>::basic_ifstream(const 
std::basic_ifstream<_Elem,_Traits> &)'
        with
        [
            _Elem=char,
            _Traits=std::char_traits<char>
        ]




Raj

"Doug Harrison [MVP]" <dsh@mvps.org> wrote in message 
news:q6fun2tjdnfke37dodjmf00u8kdugk4ms8@4ax.com...
> On Tue, 12 Dec 2006 18:22:47 -0500, "Raj Kulkarni"
> <rajk2000@msn.com.invalid> wrote:
>
>>I am attempting to compile a project in Visual Studio 2005 which compiles
>>and links properly in VC++ 6.0.  It seems to have problems with C++ i/o
>>functions.  Here is the error I get:
>>
>>g:\src\analyzer\digitdialpages.h(136) : error C2146: syntax error : 
>>missing
>>';' before identifier 'm_InFile'
>>Line 136:    ifstream m_InFile;
>>
>>The statment:  include <fstream> is at the top of the source file.
>>
>>Some assistance would be helpful.  We didn't have any problems with using
>>ifstream or ofstream in VC++ 6.0.  Thanks.
>
> Use std::ifstream, and read up on namespaces. See also:
>
> How to: Upgrade Projects from Previous Versions of Visual C++
> http://msdn2.microsoft.com/en-us/library/kyb7zzw4(VS.80).aspx
>
> VC6 -> VC2005 is a big jump. The old <iostream.h> headers have gone away,
> and you may have some issues moving to the standard <iostream> family.
>
> -- 
> Doug Harrison
> Visual C++ MVP 


0
rajk2000 (39)
12/13/2006 8:40:23 PM
On Wed, 13 Dec 2006 15:40:23 -0500, "Raj Kulkarni"
<rajk2000@msn.com.invalid> wrote:

>I tried your advice, and replaced "ifstream" with "std::ifstream".  I also 
>replaced instances of "ofstream" with "std::ofstream".  Those syntax errors 
>were resolved.
>When I added "std" to the following statement:  m_InFile.open(m_sFileName, 
>ios::in | ios::binary);
>which became
>    m_InFile.open(m_sFileName, std::ios::in | std::ios::binary);
>
>I get the following errors:
>
>g:\program files\microsoft visual studio 8\vc\include\fstream(675) : error 
>C2248: 'std::basic_ios<_Elem,_Traits>::basic_ios' : cannot access private 
>member declared in class 'std::basic_ios<_Elem,_Traits>'
>        with
>        [
>            _Elem=char,
>            _Traits=std::char_traits<char>
>        ]
>        g:\program files\microsoft visual studio 8\vc\include\ios(151) : see 
>declaration of 'std::basic_ios<_Elem,_Traits>::basic_ios'
>        with
>        [
>            _Elem=char,
>            _Traits=std::char_traits<char>
>        ]
>        This diagnostic occurred in the compiler generated function 
>'std::basic_ifstream<_Elem,_Traits>::basic_ifstream(const 
>std::basic_ifstream<_Elem,_Traits> &)'
>        with
>        [
>            _Elem=char,
>            _Traits=std::char_traits<char>
>        ]

Can you post a small, compilable fragment that demonstrates the problem?

-- 
Doug Harrison
Visual C++ MVP
0
dsh (2498)
12/15/2006 3:34:02 AM
Reply:

Similar Artilces:

Problem with ifstream
Hello I am using the fstream.h header included with Visual C++ .NET 2003. I create an object of the type ifstream which I use the function load to load a file into the stream. Now what function can be used to tell me when the end of file has been reached? Thanks in advance Sincerely James Simpso Straightway Technologie http://www.straightwaytech.com ...

ifstream in MFC
I am trying to write an MFC application to load a .map file(half life map) in to menu, I have ran in to difficulty using the CArchive class to access a file for input as the next data type int the file(e.g. brush, plane attribute etc.) cannot be predicted completely and so I have to check the next character to find the next datatype, the CArchive objecct however has no putback function if an unexpected object is found. I'm sure there is away around this but I would rather use the good old fstream classes, but I seem unable to use these in MFC as when debugging the code seems to sto...

MFC and ifstream
Hi, I have a MFC CFormView doc/view program made with the app wizard. I'm using VS 2002.NET. After a long while trying to figure out why I was getting obscure linker errors, I narrowed it down to this line: std::ifstream inFile; If I comment that line out, everything works. But when I add it and build, I get errors like: FluidEditor error LNK2005: "public: __thiscall std::_Lockit::_Lockit(int)" (??0_Lockit@std@@QAE@H@Z) already defined in ChaosEngine.lib(Heightmap.obj) FluidEditor error LNK2005: ___argc already defined in libcmtd.lib(crt0dat.obj) FluidEditor error LNK2005...

VC++ 2005
I am attempting to compile a project in Visual Studio 2005 which compiles and links properly in VC++ 6.0. It seems to have problems with C++ i/o functions. Here is the error I get: g:\src\analyzer\digitdialpages.h(136) : error C2146: syntax error : missing ';' before identifier 'm_InFile' Line 136: ifstream m_InFile; The statment: include <fstream> is at the top of the source file. Some assistance would be helpful. We didn't have any problems with using ifstream or ofstream in VC++ 6.0. Thanks. On Tue, 12 Dec 2006 18:22:47 -0500, "Raj Kulkarni...

Ifstream question
Hello I was wondering what function I can use in the visual C++ .NET 2003 header fstream.h , when I have already create an object of type ifstream that will check to see if the end of file or EOF has been reached yet. None of the standard STL functions appear to be there. Thanks in advance Sincerely James Simpso Straightway Technologie http://www.straightwaytech.com ...