Click to See Complete Forum and Search --> : #include <fstream.h> no longer works???


Rob McVicar
April 13th, 2004, 09:36 AM
Hey all.

I have a program that I did in VS .NET 2002 that I have just converted to 2003 (since I don't have 2002 any more). I go to compile the wretched thing and it tells me that I cannot open the #include <FSTREAM.H> file, I guess it no longer exists by the looks of things.

I tried using the #include <fstream> but that does not work. I get errors for all of the ifstream commands, binary statements, input_file statments, and well you can get the picture.

I really don't have the time to rewrite this whole program and I need it out today PLEASE HELP!

Thanks to you all!

Rob McVicar
April 13th, 2004, 09:38 AM
Sorry for the confustion in my original post, i forgot that the open & close carrots remove the thing inside. I am trying to use the FSTREAM.H include file. VisualStudio.net 2003 no longer supports this however.

Once again please help me in using this! I need to use the same commands I have I just need to know how to get the include file working with these items.

Thanks again

Paul McKenzie
April 13th, 2004, 09:49 AM
The fstream.h is non-standard, and it looks as if it is officially gone from VC++ Net.

The proper include file is "fstream" (no .h) Also, you need to realize that the namespace is std. So you need to prepend all of your variables that use fstream with std::, or if it is in your CPP source file, "using namespace std;" is adequate.

Regards,

Paul McKenzie

Rob McVicar
April 13th, 2004, 10:07 AM
Paul,

Thanks very much! When you mention "using namespace std;" You mean like this?

"using ifstream input_file;" or just putting using namespace std; at the top of the function?

I ask because all of this stuff is in my cpp files.


Thanks again for you help!

Paul McKenzie
April 13th, 2004, 11:22 AM
In your cpp file, it would be something like this:

#include < fstream >

using namespace std;

//..code

If it is your header file, I do not recommend using the "using namespace std". Instead, you prepend "std::" to all of the types and classes used by fstream:

// In you h file
#include < fstream >

class foo
{
std::ifstream f; // for example
};

This should be discussed in any good C++ book, much better and thorough than I can. It is also in the CodeGuru FAQ (namespaces).

Regards,

Paul McKenzie

Rob McVicar
April 13th, 2004, 11:30 AM
Got it working, Paul.

Thanks again for all your help!

Andreas Masur
April 13th, 2004, 02:59 PM
Originally posted by Paul McKenzie
The fstream.h is non-standard, and it looks as if it is officially gone from VC++ Net.

Yes...they have removed them from their latest compiler. :cool:

Andreas Masur
April 13th, 2004, 03:01 PM
Originally posted by Paul McKenzie
It is also in the CodeGuru FAQ (namespaces).

Well...unfortunately I did not add this to the FAQs yet...

The following shows you the four different methods to map a namespace...

// Using the full member name, including the namespace it belongs to:
std::cout << "Hello World";


// By taking advantage of Using-Declarations:
using std::cout; // This declares cout in the current
// scope as synonym for std::cout
cout << "Hello World";


// By taking advantage of Using-Directives:
using namespace std; // Which specifies that the current
// scope can refer to names in the
// 'std' namespace without using
// full qualifiers. This is mostly
// used when porting legacy code.
cout << "Hello World";


// Using aliases:
namespace X
{
namespace Y
{
class Z { ... };
}
}

X::Y::Z // The full qualifier for 'Z' is
// 'X::Y::Z'

namespace w = X::Y; // This declares 'w' as an alias for
// namespace 'X::Y'

w::Z // Access 'Z' using 'w::Z'