Newbie question : problem defining ofstreamproblem defining ofstream in Win32 C++ program
Page 1 of 1
10 Replies - 1756 Views - Last Post: 02 June 2007 - 09:38 PM
#1
Newbie question : problem defining ofstream
Posted 10 February 2007 - 10:38 AM
I'm creating a front end dialog based program in Windows XP with Visual C++ 2005. I'm trying to create an ofstream text file in one of the functions. I have this at the top of the code file :
[code]
using namespace system;
#include <fstream>
#include "stdafx.h"
#include "MPEG4FrontEnd.h"
#include "MPEG4FrontEndDlg.h"
[code]
and my code for creating the stream is :
[code]
void CMPEG4FrontEndDlg::CmdRemove()
{
BOOL islogfile;
CFile testlogfile;
int logmsgsize;
ofstream logfile; // here it is
CString logtext;
UINT copy_if_unpacked;
CString nyttnavn;
..more unimportant code
}
[code]
when I try to compile this, I get the following message at the ofstream creation :
d:\programmering\projects\mpeg4frontend\mpeg4frontend\mpeg4frontenddlg.cpp(427) : error C2065: 'ofstream' : undeclared identifier
I checked that the include should only be <fstream> (there is no fstream.h file, only an fstream file without an .h ending) and I've tried creation other streams than the ofstream as well, with the same result. What am I doing wrong here ? Some kind of setting perhaps ?
Replies To: Newbie question : problem defining ofstream
#2
Re: Newbie question : problem defining ofstream
Posted 10 February 2007 - 10:48 AM
This post has been edited by realNoName: 10 February 2007 - 10:49 AM
#3
Re: Newbie question : problem defining ofstream
Posted 10 February 2007 - 10:50 AM
using namespace std;
#4
Re: Newbie question : problem defining ofstream
Posted 10 February 2007 - 11:06 AM
realNoName, on 10 Feb, 2007 - 10:48 AM, said:
Thanks for replying. The top of my file now looks like this :
// MPEG4FrontEndDlg.cpp : implementation file
//
using std::ofstream;
using namespace system;
#include <fstream>
#include "stdafx.h"
#include "MPEG4FrontEnd.h"
#include "MPEG4FrontEndDlg.h"
[code]
and the declaration of ofstream has not changed :
[code]
void CMPEG4FrontEndDlg::CmdRemove()
{
BOOL islogfile;
CFile testlogfile;
int logmsgsize;
ofstream logfile; // here it is
CString logtext;
UINT copy_if_unpacked;
CString nyttnavn;
...more uniportant code
[code]
still get the followin message :
error C2065: 'ofstream' : undeclared identifier
Am I using the tip wrong or is there another solution to this ?
[quote name='horace' post='201467' date='10 Feb, 2007 - 10:50 AM']
try
[code]
using namespace std;
[/quote]
Didn't work that either
#5
Re: Newbie question : problem defining ofstream
Posted 10 February 2007 - 12:08 PM
so it should look like this
#include <fstream> #include "stdafx.h" #include "MPEG4FrontEnd.h" #include "MPEG4FrontEndDlg.h" using std::ofstream;
and you dont need to include both std::ofstream and namespace::std just one of them
This post has been edited by realNoName: 10 February 2007 - 12:14 PM
#6
Re: Newbie question : problem defining ofstream
Posted 10 February 2007 - 12:15 PM
realNoName, on 10 Feb, 2007 - 12:08 PM, said:
so it should look like this
#include <fstream> #include "stdafx.h" #include "MPEG4FrontEnd.h" #include "MPEG4FrontEndDlg.h" using std::ofstream;
and you dont need to include both std::ofstream and namespace::std
namespace::std includes most of the common things like cout,cin,endl,ect...
std::ofstream just includes the out stream
My code in the beginning now looks like this :
[code]
#include <fstream>
#include "stdafx.h"
#include "MPEG4FrontEnd.h"
#include "MPEG4FrontEndDlg.h"
using std::ofstream;
#ifdef _DEBUG
#define new DEBUG_NEW
#endif
[code]
and I now get the message :
error C2039: 'ofstream' : is not a member of 'std'
and it "points" to the "using std::ofstream" line
#7
Re: Newbie question : problem defining ofstream
Posted 10 February 2007 - 12:20 PM
This post has been edited by realNoName: 10 February 2007 - 12:21 PM
#8
Re: Newbie question : problem defining ofstream
Posted 10 February 2007 - 12:24 PM
realNoName, on 10 Feb, 2007 - 12:20 PM, said:
Tried using namespace std; both over and under the include file, but I the just get the usual "error C2065: 'ofstream' : undeclared identifier' at the line where I try to declare an ofstream
#9
Re: Newbie question : problem defining ofstream
Posted 10 February 2007 - 01:26 PM
this is what i did to test
Quote
using std::ofstream;
int main()
{
ofstream logfile;
logfile.open("test.txt");
logfile << "Just a test";
logfile.close();
return 0;
}
This post has been edited by realNoName: 10 February 2007 - 01:36 PM
#10
Re: Newbie question : problem defining ofstream
Posted 10 February 2007 - 01:32 PM
realNoName, on 10 Feb, 2007 - 01:26 PM, said:
this is what i did to test
Quote
using std::ofstream;
int main()
{
ofstream logfile;
logfile.open("test.txt");
logfile << "Just a test";
logfile.close();
return 0;
}
Thanx for trying to help. As I said before, I'm using MFC in WinXP to create this program (a dialogbased windows program), so there might be som settings or something else I don't know about that does this. The test you did are in standard C/C++ programming, so that may be the reason why it doesn't work in my program. Anyway, thanks again for trying.
#11
Re: Newbie question : problem defining ofstream
Posted 02 June 2007 - 09:38 PM
|
|

New Topic/Question
Reply




MultiQuote




|