By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,930 Members | 1,492 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,930 IT Pros & Developers. It's quick & easy.

Conflict with <fstream> and <vector>

P: n/a
Hi,

I have been using <fstream.h> in stdafx.h,(i'm using MFC) to output to
text files. I have now started to use vectors and when i added

#include <vector>
using namespace std;

to stdafx.h, I found that to compile i had to change <fstream.h> to
<fstream> to get it to compile.

When i run my program i have found that when i do something like:

CString filename,test;
test = "This is a test";
ofstream opdfs;
filename = "C:\\Filepath\\test.txt";

opdfs.open(filename, ios::out|ios::app);
opdfs << test <<endl;
opdfs.close();

It does not write the string to the file but a hex representation
0087385C.

Can anyone tell me why this is happening and how i can solve it?

Thanks In Advance
Macca
Jul 22 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a

"Macca" <ma***********@yahoo.co.uk> wrote in message
news:e3**************************@posting.google.c om...
Hi,

I have been using <fstream.h> in stdafx.h,(i'm using MFC) to output to
text files. I have now started to use vectors and when i added

#include <vector>
using namespace std;

to stdafx.h, I found that to compile i had to change <fstream.h> to
<fstream> to get it to compile.
<fstream.h> is a non-standard header file. Don't use it.

When i run my program i have found that when i do something like:

CString filename,test;
test = "This is a test";
ofstream opdfs;
filename = "C:\\Filepath\\test.txt";

opdfs.open(filename, ios::out|ios::app);
opdfs << test <<endl;
opdfs.close();

It does not write the string to the file but a hex representation
0087385C.

Can anyone tell me why this is happening and how i can solve it?


CString is a non-standard class, use std::string instead (header file
<string>)

I would imagine that some sort of invalid conversion to a pointer is
happening. Try being explicit

opdfs << (const char*)test <<endl;

but better still start using std::string, it is much better for nearly all
purposes than CString.

john
Jul 22 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.