Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / Managed C++ / June 2005

Tip: Looking for answers? Try searching our database.

ofstream in C++ 2003

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Howard Kaikow - 01 Jun 2005 10:12 GMT
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;
}

Signature

http://www.standards.com/; See Howard Kaikow's web site.

Martin Richter [MVP] - 01 Jun 2005 12:01 GMT
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]
Signature

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

Howard Kaikow - 01 Jun 2005 12:43 GMT
> 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?
adebaene@club-internet.fr - 01 Jun 2005 13:02 GMT
Howard Kaikow a écrit :
> > The STL is located in the namespace std!
> > // Insert this here
[quoted text clipped - 3 lines]
>
> 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

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.