473,385 Members | 2,274 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,385 software developers and data experts.

Conflict with <fstream> and <vector>

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
1 2107

"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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

10
by: John Tiger | last post by:
Can anybody have idea about the difference between #include <iostream.h> and #include <iostream>. Is later one valid statement on any compiler. I tried compiling on MSVC second statement give...
5
by: {AGUT2} {H}-IWIK | last post by:
Hi, I'm trying to pass my vector to a function external to my main(), but my compiler is complaining. FYI, the struct for the facetInfo works perfectly, it's just the vector passing. A quick...
12
by: Gaurav | last post by:
Hello I have a program that basically inverts the contents of files except first line. It compiles fine but gives me core dump on running. If i comment temp.clear() it runs fine, but i need...
11
by: Charles L | last post by:
I have read that the inclusion of <fstream.h> makes the inclusion of <iostream.h> unnecessary. Is this correct? Charles L
3
by: Juicer_X | last post by:
Hello everyone, I've been working with the STL Containers for a little while now, but in the middle of working on a small "Markov Chain" class I realized that I wanted to modify my frequency...
2
by: ehui928 | last post by:
hi, everybody I am a newbie in STL. When I compile the following program under gcc4.0, I got a the following errors. I wonder whether the form of list< vector<string> > is correct in STL ? //...
5
by: Etrex | last post by:
Hello, This is my first attempt at a c++ program, and it is a long post, please bear with me. I'm trying to read in a text file containing a firewall log, make the information...
6
by: arnuld | last post by:
This works fine, I welcome any views/advices/coding-practices :) /* C++ Primer - 4/e * * Exercise 8.9 * STATEMENT: * write a program to store each line from a file into a *...
2
by: subramanian100in | last post by:
Consider the following piece of code: #include <iostream> #include <fstream> #include <vector> #include <string> #include <utility> #include <iterator> #include <algorithm> int main()
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.