Probably me being stupid - fstream

C

Catweasel

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
 
G

Guest

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"
.....
 
C

Catweasel

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 said:
::~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 said:
::~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.




http://www.newsfeed.com The #1 Newsgroup Service in the World! >100,000 Newsgroups
 
N

Narcing

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---fstream.htm

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

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