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.giganews.com!nntp.giganews.com!newspeer1.dllstx09.us.to.verio.net!news.verio.net!newsread1.dllstx09.us.to.verio.net.POSTED!53ab2750!not-for-mail
From: Victor Bazarov <
[email protected]>
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: <
[email protected]>
In-Reply-To: <
[email protected]>
Content-Type: text/plain; charset=us-ascii; format=flowed
Content-Transfer-Encoding: 7bit
Lines: 40
Message-ID: <
[email protected]>
Date: Wed, 28 Jul 2004 17:29:36 -0400
NNTP-Posting-Host: 149.65.2.103
X-Complaints-To: (e-mail address removed)
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
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:
ut | ios:
ut); ^^^^^^^^^^^^^^^^^^^^^^ 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.