472,143 Members | 1,525 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,143 software developers and data experts.

VC++ 2005 - Compilation Errors using "ifstream"

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_ifstrea m(const
std::basic_ifstream<_Elem,_Traits&)'
with
[
_Elem=char,
_Traits=std::char_traits<char>
]


Raj

"Doug Harrison [MVP]" <ds*@mvps.orgwrote in message
news:q6********************************@4ax.com...
On Tue, 12 Dec 2006 18:22:47 -0500, "Raj Kulkarni"
<ra******@msn.com.invalidwrote:
>>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 <fstreamis 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/lib...w4(VS.80).aspx

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

--
Doug Harrison
Visual C++ MVP


Dec 14 '06 #1
4 12722
marathoner 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_ifstrea m(const
std::basic_ifstream<_Elem,_Traits&)'
with
[
_Elem=char,
_Traits=std::char_traits<char>
]
This looks like the compiler is trying to generate a copy constructor for
std::ifstream. Quite correctly, this doesn't work as the stream types are
not copyable.
Bo Persson
Dec 14 '06 #2
I guess what I should is to remove all references to C++ i/o and replace
them with C i/o (fopen, fclose, fprintf, ...). Is that correct?

Marathoner
"Bo Persson" <bo*@gmb.dkwrote in message
news:4u*************@mid.individual.net...
marathoner 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_ifstre am(const
std::basic_ifstream<_Elem,_Traits&)'
with
[
_Elem=char,
_Traits=std::char_traits<char>
]

This looks like the compiler is trying to generate a copy constructor for
std::ifstream. Quite correctly, this doesn't work as the stream types are
not copyable.
Bo Persson


Dec 15 '06 #3
marathoner wrote:
I guess what I should is to remove all references to C++ i/o and replace
them with C i/o (fopen, fclose, fprintf, ...). Is that correct?
No, you should figure out what you are doing wrong. Never "sweep a
problem under the rug."

I suggest (based on Bo's observation) that you are trying to pass an
ostream or istream object by value. You must always pass them by reference.

David Wilkinson
Dec 15 '06 #4
marathoner 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);
You need:

std::ios_base::in | std::ios_base::binary

-cd
Dec 15 '06 #5

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

5 posts views Thread by Andreas Lassmann | last post: by
2 posts views Thread by Steven T. Hatton | last post: by
1 post views Thread by Robbie Hatley | last post: by
5 posts views Thread by Denis Petronenko | last post: by
9 posts views Thread by Xian | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.