header files in VC++.NET

A

Agos

I'm trying to learn VC++.NET. I used till now Borland C++ Builder 6.
I had a program starting like this:

#include <fstream.h>
#define TEMP_FILES 200
......
.......
fstream chunk_file[TEMP_FILES];

With Borland and g++ I had no problems with these lines instead VC++.NET
tells me that can't find #include <fstream.h>
I saw that it works with
#include <fstream> (without .h)
but if I use the header files this way I get an error in this declaration:

fstream chunk_file[TEMP_FILES];

So if I try to build this short program:
=========================================
#include "stdafx.h"
#include <fstream>
#define TEMP_FILES 200

int _tmain(int argc, _TCHAR* argv[])
{
fstream chunk_file[TEMP_FILES];
return 0;
}
=====================================================

VC++ gives me these errors:

error C2065: 'fstream' : undeclared identifier
(in fatc it knows what fstream is: A type basic_fstream specialized on char
template parameters.)
error C2146: syntax error : missing ';' before identifier 'chunk_file'
error C2065: 'chunk_file' : undeclared identifier

Where am I wrong and why these lines wokrks with Borland and g++?

Thank you very much

Agos
 
R

Ronald Laeremans [MSFT]

Agos said:
I'm trying to learn VC++.NET. I used till now Borland C++ Builder 6.
I had a program starting like this:

#include <fstream.h>
#define TEMP_FILES 200
......
.......
fstream chunk_file[TEMP_FILES];

With Borland and g++ I had no problems with these lines instead VC++.NET
tells me that can't find #include <fstream.h>
I saw that it works with
#include <fstream> (without .h)
but if I use the header files this way I get an error in this declaration:

fstream chunk_file[TEMP_FILES];

So if I try to build this short program:
=========================================
#include "stdafx.h"
#include <fstream>
#define TEMP_FILES 200

int _tmain(int argc, _TCHAR* argv[])
{
fstream chunk_file[TEMP_FILES];
return 0;
}
=====================================================

VC++ gives me these errors:

error C2065: 'fstream' : undeclared identifier
(in fatc it knows what fstream is: A type basic_fstream specialized on char
template parameters.)
error C2146: syntax error : missing ';' before identifier 'chunk_file'
error C2065: 'chunk_file' : undeclared identifier

Where am I wrong and why these lines wokrks with Borland and g++?

Thank you very much

Agos
Because the version of the Borland compielr and its libraries are not
conformant to the C++ standard.

fstream does not exist. std::fstream is the class in the standard.

using namespace std;

is the quick fix.

Ronald Laeremans
Visual C++ team
 
A

Agos

Thank you vgery much :)
Just one thing .... also g++ compile that.

And one information: why C++ standard decided to eliminate the ".h" from
header files?

Anyway thank you indeed again.

Agos

Ronald Laeremans said:
Agos said:
I'm trying to learn VC++.NET. I used till now Borland C++ Builder 6.
I had a program starting like this:

#include <fstream.h>
#define TEMP_FILES 200
......
.......
fstream chunk_file[TEMP_FILES];

With Borland and g++ I had no problems with these lines instead VC++.NET
tells me that can't find #include <fstream.h>
I saw that it works with
#include <fstream> (without .h)
but if I use the header files this way I get an error in this
declaration:

fstream chunk_file[TEMP_FILES];

So if I try to build this short program:
=========================================
#include "stdafx.h"
#include <fstream>
#define TEMP_FILES 200

int _tmain(int argc, _TCHAR* argv[])
{
fstream chunk_file[TEMP_FILES];
return 0;
}
=====================================================

VC++ gives me these errors:

error C2065: 'fstream' : undeclared identifier
(in fatc it knows what fstream is: A type basic_fstream specialized on
char template parameters.)
error C2146: syntax error : missing ';' before identifier 'chunk_file'
error C2065: 'chunk_file' : undeclared identifier

Where am I wrong and why these lines wokrks with Borland and g++?

Thank you very much

Agos
Because the version of the Borland compielr and its libraries are not
conformant to the C++ standard.

fstream does not exist. std::fstream is the class in the standard.

using namespace std;

is the quick fix.

Ronald Laeremans
Visual C++ team
 
C

Carl Daniel [VC++ MVP]

Agos said:
Thank you vgery much :)
Just one thing .... also g++ compile that.

That doesn't say much. g++ will compile lots of stuff that's not standard
compliant.
And one information: why C++ standard decided to eliminate the ".h" from
header files?

The ".h" versions of the iostreams header files were never standards
compliant. The original standard in 1998 defines only the versions without
the ".h". The ".h" versions are pre-standard, i.e. over 7 years out of
date, and support for them was deprecated in VC7 and dropped altogether in
VC7.1.

-cd
 
A

Agos

Thank you

Agostino

Carl Daniel said:
That doesn't say much. g++ will compile lots of stuff that's not standard
compliant.


The ".h" versions of the iostreams header files were never standards
compliant. The original standard in 1998 defines only the versions
without the ".h". The ".h" versions are pre-standard, i.e. over 7 years
out of date, and support for them was deprecated in VC7 and dropped
altogether in VC7.1.

-cd
 

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