Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

error C2065: 'ofstream' : undeclared identifier

Status
Not open for further replies.

delangelMO

Programmer
Feb 24, 2003
3
MX
My code is

#include <windows.h> /* for far etc. */
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <fstream.h> /* O.M. del Angel Para generar un archivo de salida */
#include <iostream.h> /* O.M. del Angel Para generar un archivo de salida */

.....

VOID DispStr(LPBYTE pBufIp)
{
char str[256]; /*O.M. del Angel*/

memset(pTemp, '\0', TEMP_SIZE);
memcpy(pTemp, pBufIp, pMixHd->dwLen1);
TRACE(( TC_VD, TT_API2, &quot;The String Received is %s&quot;, pTemp));

/* O. M. del Angel */
ofstream a_file (&quot;example.txt&quot;);
//Creates an instance of ofstream, and opens example.txt
a_file << pTemp <<&quot;\n&quot;;
a_file.close();
//Closes up the file

}

I get the error C2065: 'ofstream' : undeclared identifier in the line

ofstream a_file (&quot;example.txt&quot;);

¿Somebody helpme?
 
I have just tried your code on my compiler and it worked OK.
Perhaps it is one of your compiler settings. Adonai :)
 
make sure you have

using namespace std; at the beginning of the file (i assume this is what Adonai did without knowing it. If you make a console app with mfc support, this is at the beginning of the file. Also, you can use std::ifstream(&quot;example.txt&quot;); if you dont want the namespace stuff.


Matt
 
>> using namespace std;

uh, no he's not using the STL stream library.
 
Jeez, just one question though... when I use scope resolution with std:: and mfc opens the list, why do I see ofstream there?

Looking at the code, I would comment out the TRACE first, I dont know what the first 2 args are but I dont think the trace is valid. Because it is a macro, you may be getting issues with that and not the fstream stuff.

Matt
 
Zyrenthian,

hopefully ur seeing the autocomplete for the old C++ io stream library. But i wouldn't trust the autocomplete completely. < errr... redundant > :)

-pete
 
Oh I agree... MFC can not always be trusted. Just figured it was like a std::cout problem. After playing with it I now recall that I too had issues with iostream unless i DID NOT use mfc. I instead opt'ed for using CStdioFile with WriteString and ReadString ops.

Matt
 
pete - >> old C++ io stream library

Zyrenthian - >> MFC can not always be trusted

i hope i did not confuse you. the old C++ io stream library has nothing to do with MFC.

-pete
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top