Click to See Complete Forum and Search --> : What replaces <strstrea.h> <fstream.h> <iomanip.h> in .Net


mrcomplex
August 2nd, 2004, 08:31 PM
Hi, I have the following code that works in VC++ 6.0 but it doesn't in .NET. Can anybody please tell me what's the equivalent for <strstrea.h>, <fstream.h>, <iomanip.h> in .Net? I need those header files for ostrstream, hex, setfill, setw (see code below) thanks.

#include <strstrea.h>
#include <fstream.h>
#include <iomanip.h>

char * FillBlock( short * Data, int count )
{
static char s[511];
ostrstream TextFile(s, sizeof s);
BOOL InsertEOL=FALSE;
for (int i=0; i<count; i++)
{
if (( i%8==0 )&&InsertEOL)
TextFile<<"\r\n";
InsertEOL=TRUE;
TextFile<<hex<<"0x"<<setfill('0')<<setw(4)<<Data[i]<<"\t";
}
TextFile<<ends;
return s;
}

Philip Nicoletti
August 2nd, 2004, 08:37 PM
#include <fstream>
#include <iomanip>
#include <strstream>


Note, everything in the standard library is in namespace std.
So you need to either qualify the functions or do a "using". Eample:



std::cout << "hello world\n";

// or

using namespace std;

cout << "hello world\n";


Also note, <strstream> is deprecated (still in C++ standard, but might not
be in the future). <sstream> is recomended.

kmmoens
August 3rd, 2004, 05:08 AM
The .h extentions for these headers are deprecated (as defined in C++ standard).

You should use:
#include <fstream>
#include <iomanip>

Please note that probably you'll have to change somethings, since all members of these files are now in the std namespace.

So std::fstream, std::hex,...

Andreas Masur
August 3rd, 2004, 05:35 AM
[ Merged threads ]

mrcomplex
August 3rd, 2004, 01:36 PM
Thanks guys, that works! :)

Andreas Masur
August 3rd, 2004, 01:43 PM
Almost all compilers, even those complying with ISO standard, allow the use of the traditional header files (like iostream.h, stdlib.h, etc). Nevertheless, the ISO standard has completely redesigned these libraries taking advantage of the template feature and following the rule to declare all the functions and variables under the namespace 'std'.

The standard has specified new names for these "header" files, basically using the same name for C++ specific files, but without the ending '.h'. For example, 'iostream.h' becomes 'iostream'.

If you use the ISO-C++ compliant include files you have to bear in mind that all the functions, classes and objects will be declared under the 'std' namespace.