473,320 Members | 1,945 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

ofstream in C++ 2003

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::out);
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;
}

--
http://www.standards.com/; See Howard Kaikow's web site.
Nov 17 '05 #1
3 1372
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]
--
Martin Richter [MVP] WWJD
"In C we had to code our own bugs. In C++ we can inherit them."
FAQ : http://www.mpdvc.de
Samples: http://www.codeguru.com http://www.codeproject.com
Nov 17 '05 #2
"Martin Richter [MVP]" <ma************@mvps.org> wrote in message
news:d7**********@news.grutzeck.de...
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?
Nov 17 '05 #3


Howard Kaikow a écrit :
"Martin Richter [MVP]" <ma************@mvps.org> wrote in message
news:d7**********@news.grutzeck.de...
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?


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

Nov 17 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: red floyd | last post by:
Is there any way to retrieve the filename given to a std::ofstream (passed in constructor or in ofstream::open())? Or, should I derive from ofstream (should probably be a template to handle...
3
by: Chase Bradford | last post by:
Hey all I have a class Foo, and I'm trying to overload the << operator for both the ostream and ofstream for it. This way I should have two seperate formats for output, one for files and another...
2
by: Steven C | last post by:
ofstream blah; IS: if (blah == NULL) { } THE SAME AS:
2
by: Marina | last post by:
I get an "access violation" when I use someting like this: @@@@@@@@@@@@@@ string tempo; const char *output; vector <ofstream> outs(3); .... .... open_output=(const char *)tempo.c_str();...
2
by: slyphiad | last post by:
i'm kinda new at c++ so be patient ^_^ i was just wondering if u guys could help me to solve this problem that i had. i'm trying to create 5 sequential files using ofstream. this is what i...
5
by: Squid Seven | last post by:
I'm trying to use a pointer to an ofstream object and having problems: ofstream *sessionFile = NULL; if( directory == "" ) sessionFile = new ofstream( fileName.c_str(), ios::out ); else {
5
by: Gary Wessle | last post by:
Hi I have a map<string, doublem_temperatures which gets updated often. I need to save the data to files corresponding to each string each time the map is updated, I am expecting about 80 files...
5
by: Joe Hesse | last post by:
Hi, I have a C++ function that writes to an ofstream object. I would like to sometimes use it to write to cout. I realize that cout is of type ostream which is not ofstream. Since cout is "kind...
15
by: aaragon | last post by:
Hello, does anyone have a clue about this error? and how to solve it? It seems to be trivial to me, but not for the compiler. I'm using g++ 4.2 on an Ubuntu Linux system: // main() .......
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.