ofstream in C++ 2003

H

Howard Kaikow

I was having difficulty trying to use ofstream in C++ 2003, so I booted to
another system that has VS C++ 6 and got the code working.

I then import the project into VS C++ .NET 2002. Code ran as expected. There
was a warning that the code was deprecated.

I then import the .NET 2002 project into C++ .NET 2003.
First, it stated that two libraries were not present.
So I removed the .h, the libraries were found, but htere were a whole lot of
errors ar build time.

What do I need to do to get the following running in C++ .NET 2003?

#include "stdafx.h"
#include <iostream>
#include <fstream>
#include <stdlib.h>

int APIENTRY WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow)
{
// TODO: Place code here.
char *buffer = "Bagels and lox";
ofstream outfile("stuff.dat", ios::blush:ut);
if (!outfile)
{
cerr << "Cannot open file";
exit(-1);
}
outfile << buffer << endl;
outfile.close();

ofstream bFile("binary.dat", ios::binary);
bFile.write(buffer, sizeof buffer);
bFile.close();
return 0;
}
 
M

Martin Richter [MVP]

Hallo Howard Kaikow!
I then import the .NET 2002 project into C++ .NET 2003.
First, it stated that two libraries were not present.
So I removed the .h, the libraries were found, but htere were a whole lot of
errors ar build time.

The STL is located in the namespace std!
What do I need to do to get the following running in C++ .NET 2003?

#include "stdafx.h"
#include <iostream>
#include <fstream>
#include <stdlib.h>

// Insert this here
using namespace std;
int APIENTRY WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
[snip]
 
H

Howard Kaikow

Martin Richter said:
The STL is located in the namespace std!
// Insert this here
using namespace std;


Thanx.

Did MSFT ever explain why they deprecated/removed those libraries?
 
A

adebaene

Howard Kaikow a écrit :
Thanx.

Did MSFT ever explain why they deprecated/removed those libraries?

I guess because the old iostream library :
- was non-standard and non-specified.
- was dangerously close to the new, standard iostream library (both
syntaxically and semantically), with just enough subtle differences to
make it easy to step on once foot when using one instead of the other.
- didn't provide any more capability than the new, standard one.

Arnaud
MVP - VC
 

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