VC++ 2005 - Compilation Errors using "ifstream"

M

marathoner

I tried your advice, and replaced "ifstream" with "std::ifstream". I also
replaced instances of "ofstream" with "std::blush:fstream". 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
 
B

Bo Persson

marathoner said:
I tried your advice, and replaced "ifstream" with "std::ifstream". I also
replaced instances of "ofstream" with "std::blush:fstream". 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>
]

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
 
M

marathoner

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 said:
marathoner said:
I tried your advice, and replaced "ifstream" with "std::ifstream". I also
replaced instances of "ofstream" with "std::blush:fstream". 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>
]

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
 
D

David Wilkinson

marathoner said:
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
 
C

Carl Daniel [VC++ MVP]

marathoner said:
I tried your advice, and replaced "ifstream" with "std::ifstream". I
also replaced instances of "ofstream" with "std::blush:fstream". 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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top