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

Why Doesn't C++ Accept This OFSTREAM VECTOR?

P: n/a
I get an "access violation" when I use someting like this:

@@@@@@@@@@@@@@
string tempo;
const char *output;
vector <ofstream> outs(3);
....
....
open_output=(const char *)tempo.c_str();
ofstream out0(open_output, ios::out | ios::out);
outs[0]=out0;

@@@@@@@@@@@@@@
This access violation comes only when
the line

outs[0]=out0;

is included.
Please help. I do need a vector ot "ofstream" type.

Thank you!

Marina
Jul 22 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
Marina wrote:
I get an "access violation" when I use someting like this:

@@@@@@@@@@@@@@
string tempo;
const char *output;
vector <ofstream> outs(3);
This shouldn't compile. 'ofstream' doesn't satisfy the requirement for
elements of 'vector': it is not "copy-constructible".
...
...
open_output=(const char *)tempo.c_str();
There is no need to cast it. 'c_str()' already returns const char*.
ofstream out0(open_output, ios::out | ios::out); ^^^^^^^^^^^^^^^^^^^^^^ Huh? outs[0]=out0;
There is no copy semantics for ofstream. This simply shouldn't compile.

Why can't you simply say

outs[0].open(open_output);

@@@@@@@@@@@@@@
This access violation comes only when
the line

outs[0]=out0;

is included.
Please help. I do need a vector ot "ofstream" type.


You can't have it. Create a vector of pointers to ofstream.

V
Jul 22 '05 #2

P: n/a
On Wed, 28 Jul 2004 17:29:36 -0400, Victor Bazarov
<v.********@comAcast.net> wrote:
sn-us!sn-xit-06!sn-xit-08!sn-xit-11!supernews.com!green.octanews.net!news-out.octanews.net!news.glorb.com!border1.nntp.dca.g iganews.com!nntp.giganews.com!newspeer1.dllstx09.u s.to.verio.net!news.verio.net!newsread1.dllstx09.u s.to.verio.net.POSTED!53ab2750!not-for-mail
From: Victor Bazarov <v.********@comAcast.net>
User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.6) Gecko/20040113
X-Accept-Language: en-us, en
MIME-Version: 1.0
Newsgroups: comp.lang.c++
Subject: Re: Why Doesn't C++ Accept This OFSTREAM VECTOR?
References: <du********************************@4ax.com>
In-Reply-To: <du********************************@4ax.com>
Content-Type: text/plain; charset=us-ascii; format=flowed
Content-Transfer-Encoding: 7bit
Lines: 40
Message-ID: <cV**************@newsread1.dllstx09.us.to.verio.n et>
Date: Wed, 28 Jul 2004 17:29:36 -0400
NNTP-Posting-Host: 149.65.2.103
X-Complaints-To: ab***@verio.net
X-Trace: newsread1.dllstx09.us.to.verio.net 1091050184 149.65.2.103 (Wed, 28 Jul 2004 21:29:44 GMT)
NNTP-Posting-Date: Wed, 28 Jul 2004 21:29:44 GMT
Organization: NTT/VERIO
Xref: sn-us comp.lang.c++:806351

Marina wrote:
I get an "access violation" when I use someting like this:

@@@@@@@@@@@@@@
string tempo;
const char *output;
vector <ofstream> outs(3);


This shouldn't compile. 'ofstream' doesn't satisfy the requirement for
elements of 'vector': it is not "copy-constructible".
...
...
open_output=(const char *)tempo.c_str();


There is no need to cast it. 'c_str()' already returns const char*.
ofstream out0(open_output, ios::out | ios::out);

^^^^^^^^^^^^^^^^^^^^^^ Huh?
outs[0]=out0;


There is no copy semantics for ofstream. This simply shouldn't compile.

Why can't you simply say

outs[0].open(open_output);

@@@@@@@@@@@@@@
This access violation comes only when
the line

outs[0]=out0;

is included.
Please help. I do need a vector ot "ofstream" type.


You can't have it. Create a vector of pointers to ofstream.

Thank you, Bazarov!
It worked fine.

Later...

Marina
Jul 22 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.