473,561 Members | 3,602 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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::binar y);

I get the following errors:

g:\program files\microsoft visual studio 8\vc\include\fs tream(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::ch ar_traits<char>
]
g:\program files\microsoft visual studio 8\vc\include\io s(151) : see
declaration of 'std::basic_ios <_Elem,_Traits> ::basic_ios'
with
[
_Elem=char,
_Traits=std::ch ar_traits<char>
]
This diagnostic occurred in the compiler generated function
'std::basic_ifs tream<_Elem,_Tr aits>::basic_if stream(const
std::basic_ifst ream<_Elem,_Tra its&)'
with
[
_Elem=char,
_Traits=std::ch ar_traits<char>
]


Raj

"Doug Harrison [MVP]" <ds*@mvps.orgwr ote in message
news:q6******** *************** *********@4ax.c om...
On Tue, 12 Dec 2006 18:22:47 -0500, "Raj Kulkarni"
<ra******@msn.c om.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\analyz er\digitdialpag es.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.hhead ers have gone away,
and you may have some issues moving to the standard <iostreamfamily .

--
Doug Harrison
Visual C++ MVP


Dec 14 '06 #1
4 12857
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::binar y);

I get the following errors:

g:\program files\microsoft visual studio 8\vc\include\fs tream(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::ch ar_traits<char>
]
g:\program files\microsoft visual studio
8\vc\include\io s(151) : see declaration of
'std::basic_ios <_Elem,_Traits> ::basic_ios' with
[
_Elem=char,
_Traits=std::ch ar_traits<char>
]
This diagnostic occurred in the compiler generated function
'std::basic_ifs tream<_Elem,_Tr aits>::basic_if stream(const
std::basic_ifst ream<_Elem,_Tra its&)'
with
[
_Elem=char,
_Traits=std::ch ar_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.dkwrot e in message
news:4u******** *****@mid.indiv idual.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::binar y);

I get the following errors:

g:\program files\microsoft visual studio 8\vc\include\fs tream(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::ch ar_traits<char>
]
g:\program files\microsoft visual studio
8\vc\include\i os(151) : see declaration of
'std::basic_ios <_Elem,_Traits> ::basic_ios' with
[
_Elem=char,
_Traits=std::ch ar_traits<char>
]
This diagnostic occurred in the compiler generated function
'std::basic_if stream<_Elem,_T raits>::basic_i fstream(const
std::basic_ifs tream<_Elem,_Tr aits&)'
with
[
_Elem=char,
_Traits=std::ch ar_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::binar y);
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
3179
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 "if(fileInput == '\n')?
2
3495
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: http://gcc.gnu.org/onlinedocs/libstdc++/27_io/howto.html#1 Copying a file: WRONG WAY: #include <fstream> std::ifstream IN ("input_file"); std::ofstream OUT ("output_file");
7
5535
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, with different file names each time. So i'm writing into the code to ask the user how many files, and what their names are. From each we'll read in...
1
13571
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
3225
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, but strings must be divided by ";" separator.
15
4852
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
3371
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 World!" << std::cout; -- /Xian
1
1194
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 hade the command up top it seems not to work with the writting functions or if I use it multiable times on diffrent cases I get this jump error.
2
2249
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 <stdlib.h> //needed for converting integers to strings #include <iostream> //needed for in/out commands ie. cin/cout #include <fstream> //needed to open...
0
7647
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7570
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7859
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8088
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
5472
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5187
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3600
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1181
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
896
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.