473,406 Members | 2,549 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 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 12837
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Andreas Lassmann | last post by:
is there any way to find an endline in a file? i.e: xxxxxxxxxxxxxxxxx x x x x x x x x x xxxxxxxxxxxxxxxxx is there some method in "ifstream"? or can i check it with something like...
2
by: Steven T. Hatton | last post by:
I'm still not completely sure what's going on with C++ I/O regarding the extractors and inserters. The following document seems a bit inconsistent:...
7
by: jccorreu | last post by:
I've got to read info from multiple files that will be given to me. I know the format and what the data is. The thing is each time we run the program we may be using a differnt number of files,...
1
by: Robbie Hatley | last post by:
Say I have an ifstream object, like so: #include <iostream> #include <fstream> int main(int, char* Sam) { std::ifstream Bob; Bob.open(Sam); std::string buffer; while (42)
5
by: Denis Petronenko | last post by:
Hello, how can i read into strings from ifstream? file contains values in following format: value11; val ue12; value 13; valu e21;value22; value23; etc. i need to read like file >string,...
15
by: jjh | last post by:
So with infile I have this so far: #define MAXBOOKS 9 ifstream infile("library.txt"); struct Book { title } while(true) {
9
by: Xian | last post by:
Is there a right and proper (tm) way to end a line? Thinking about portability and the mess that the 'wrong' line endings can cause. E.g. std::cout << "Hello World!\n"; or std::cout << "Hello...
1
Ajm113
by: Ajm113 | last post by:
Ok I got a game going and I want to use ifstream. But in this case since I want the user able to hit a key and it will delete or renter text witch invlolves cases it messes up on me... Like if I...
2
by: mauricesmith42 | last post by:
Sorry i know this is rather large to be posting, but in order to understand the question you have to see all the code //#include <windows.h> //needed for opening folders #include...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.