Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / Managed C++ / December 2006

Tip: Looking for answers? Try searching our database.

VC++ 2005 - Compilation Errors using "ifstream"

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
marathoner - 14 Dec 2006 20:31 GMT
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.
Bo Persson - 14 Dec 2006 21:49 GMT
> I tried your advice, and replaced "ifstream" with "std::ifstream". I also
> replaced instances of "ofstream" with "std::ofstream". Those syntax errors
[quoted text clipped - 29 lines]
>            _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
marathoner - 15 Dec 2006 13:44 GMT
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

>> I tried your advice, and replaced "ifstream" with "std::ifstream". I also
>> replaced instances of "ofstream" with "std::ofstream". Those syntax
[quoted text clipped - 35 lines]
>
> Bo Persson
David Wilkinson - 15 Dec 2006 14:14 GMT
> 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
Carl Daniel [VC++ MVP] - 15 Dec 2006 15:00 GMT
> I tried your advice, and replaced "ifstream" with "std::ifstream".  I
> also replaced instances of "ofstream" with "std::ofstream".  Those
[quoted text clipped - 3 lines]
> which became
>    m_InFile.open(m_sFileName, std::ios::in | std::ios::binary);

You need:

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

-cd

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.