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++ / April 2006

Tip: Looking for answers? Try searching our database.

Probably me being stupid - fstream

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Catweasel - 28 Jan 2004 15:00 GMT
I'm new to C++ and have been chucked in at the deep-end.

I have a C++ console app that works fine.  All I want to do is write
to file however as soon as I include the fstream library and try to
compile VS .net chucks out errors, lots of them:

c:\Program Files\Microsoft Visual Studio .NET
2003\Vc7\include\cstdio(17) : error C2143: syntax error : missing '{'
before ':'
c:\Program Files\Microsoft Visual Studio .NET
2003\Vc7\include\cstdio(17) : error C2059: syntax error : ':'
c:\Program Files\Microsoft Visual Studio .NET
2003\Vc7\include\cstdio(17) : error C2143: syntax error : missing '{'
before ':'
c:\Program Files\Microsoft Visual Studio .NET
2003\Vc7\include\cstdio(17) : error C2059: syntax error : ':'
c:\Program Files\Microsoft Visual Studio .NET
2003\Vc7\include\cstdio(17) : error C2143: syntax error : missing '{'
before ':'
c:\Program Files\Microsoft Visual Studio .NET
2003\Vc7\include\cstdio(17) : error C2059: syntax error : ':'
c:\Program Files\Microsoft Visual Studio .NET
2003\Vc7\include\cstdio(18) : error C2143: syntax error : missing '{'
before ':'
c:\Program Files\Microsoft Visual Studio .NET
2003\Vc7\include\cstdio(18) : error C2059: syntax error : ':'
c:\Program Files\Microsoft Visual Studio .NET
2003\Vc7\include\cstdio(18) : error C2143: syntax error : missing '{'
before ':'
c:\Program Files\Microsoft Visual Studio .NET
2003\Vc7\include\cstdio(18) : error C2059: syntax error : ':'
c:\Program Files\Microsoft Visual Studio .NET
2003\Vc7\include\cstdio(18) : error C2143: syntax error : missing '{'
before ':'
c:\Program Files\Microsoft Visual Studio .NET
2003\Vc7\include\cstdio(18) : error C2059: syntax error : ':'
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\cstdio
. . .
c:\Program Files\Microsoft Visual Studio .NET
2003\Vc7\include\cstdlib(19) : error C2143: syntax error : missing
'{' before ':'
c:\Program Files\Microsoft Visual Studio .NET
2003\Vc7\include\cstdlib(19) : error C2059: syntax error : ':'
c:\Program Files\Microsoft Visual Studio .NET
2003\Vc7\include\cstdlib(19) : error C2143: syntax error : missing
'{' before ':'
c:\Program Files\Microsoft Visual Studio .NET
2003\Vc7\include\cstdlib(19) : error C2059: syntax error : ':'
c:\Program Files\Microsoft Visual Studio .NET
2003\Vc7\include\cstdlib(19) : error C2143: syntax error : missing
'{' before ':'
c:\Program Files\Microsoft Visual Studio .NET
2003\Vc7\include\cstdlib(19) : error C2059: syntax error : ':'
c:\Program Files\Microsoft Visual Studio .NET
2003\Vc7\include\cstdlib(20) : error C2143: syntax error : missing
'{' before ':'
c:\Program Files\Microsoft Visual Studio .NET
2003\Vc7\include\cstdlib(20) : fatal error C1003: error count exceeds
100; stopping compilation

I included fstream not fstream.h and also set using namspace std;
after finding some reference to it on these forums.

Any help would be greatly appreaciated
- 28 Jan 2004 15:36 GMT
> I'm new to C++ and have been chucked in at the deep-end.
>
> I have a C++ console app that works fine.  All I want to do is write
> to file however as soon as I include the fstream library and try to
> compile VS .net chucks out errors, lots of them:

Typical for C++ is that it generates tons of errors that have nothing to do
with it.
Try to remember when it compiled last time, and try to remember what you did
change, just before these errors.
If that doesn't solve then try to comment out parts of the code until it
starts compiling again.
This way you have some clue where to find the cause. The biggest chance is
that you have forgotten a ";" or used ":" instead of ";", or something else
very silly.

Another cause could be that your search path to the header files are
confused, and your are loading the wrong header file, or have multiple
header files with the same name but with different code. Try a "rebuild
sollution" instead of a normal compile.

Also typical for C++ is to include the header file multiple times, confusing
the compiler.
In your header try to use the "#pragma once" in front of your

example.h file
--------------
#pragma once
   #include <string>
   #include <saaa>
   #include "nbbbbbb.h"
   .....
--------------

I am afraid that it is going to be trial and error to find out what goes
wrong.
Catweasel - 28 Jan 2004 18:00 GMT
The problem seems to have been something to do with the program being
written in C, but using the TP switch on the command line to ensure
it's treated as C++ for windows environment.  

As soon as I tried to reference fstream it weren't having any of it
and generated the errors in my previous post.  I know this is
something to do with C/C++ and VS .net (2003) .

A bit of resaerch on the net suggested I try renaming the file to
.cpp.  Brilliant! I managed to get the file to compile.  

I attempt to build the file and am confronted with errors related to
std::xyz.  I assume this is because I am using
namespace std;

Here is a sample:

[code:1:58affc7f54]Linking...
iscade_client.obj : error LNK2019: unresolved external symbol
"public: virtual __thiscall
std::ios_base::~ios_base(void)"
(??1ios_base@std@@UAE@XZ) referenced in function
"public: virtual __thiscall
std::basic_ios<char,struct
std::char_traits<char>
>::~basic_ios<char,struct
std::char_traits<char> >(void)"
(??1?$basic_ios@DU?$char_traits@D@std@@@std@@UAE@XZ)
iscade_client.obj : error LNK2019: unresolved external symbol
"public: __thiscall
std::_Mutex::~_Mutex(void)"
(??1_Mutex@std@@QAE@XZ) referenced in function
"public: virtual __thiscall
std::basic_streambuf<char,struct
std::char_traits<char>
>::~basic_streambuf<char,struct
std::char_traits<char> >(void)"
(??1?$basic_streambuf@DU?$char_traits@D@std@@@std@@UAE@XZ)
iscade_client.obj : error LNK2001: unresolved external symbol
"long const std::_BADOFF"
(?_BADOFF@std@@3JB)[/code:1:58affc7f54]

However if I take the fstream stuff out, voila it works perfectly.
Narcing - 20 Apr 2006 10:08 GMT
Hi i fact i too faced the problem and was scrating my head for three days...
after comming to your solution i tried.so , one more thing is that , when you change the project setting to compile as C++ , that wont affect the files with .C files.

so , we need to change the individual files properties to /Tp switch..
its strange that ,  there is no clue or documented properly , probably , mistake is mine !
anyways cheers to this site for solving my problem !

Have a good Day !

From http://developmentnow.com/g/42_2004_1_0_0_154131/Probably-me-being-stupid---fstr
eam.htm


Posted via DevelopmentNow.com Groups
http://www.developmentnow.com

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.