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

vector of fstream

I have (or better had) a class wich contains
a fstream (as a private member).
I made a vector of this class.
When I resize() the vector I got several error messages,
about some stuff being private int that context.
Is this gcc (3.2) specific or is there a 'official' reason for this?
thanks,
marc

Jul 19 '05 #1
2 3408
Marc Schellens wrote:
I have (or better had) a class wich contains
a fstream (as a private member).
I made a vector of this class.
When I resize() the vector I got several error messages,
about some stuff being private int that context.
Is this gcc (3.2) specific or is there a 'official' reason for this?


The C++ iostreams classes are neither CopyConstructable nor Assignable.
So iostream objects cannot reside in objects / containers that require
these properties (e.g., STL containers). For example:

struct X { std::ofstream out; }

X x1, x2;

// Invoke 'X::X(const X&)' (i.e., class X's copy constructor)
X x3(x2); // ERROR -- member 'out' is not copyable

// Invoke 'X::operator=(const X&)'
x1 = x2; // ERROR -- member 'out' is not assignable

--
Jim

To reply by email, remove "link" and change "now.here" to "yahoo"
jfischer_link5809{at}now.here.com
Jul 19 '05 #2

"Jim Fischer" <jf***************@now.here.com> wrote in message
news:_6*****************@fe01.atl2.webusenet.com.. .
Marc Schellens wrote:
I have (or better had) a class wich contains
a fstream (as a private member).
I made a vector of this class.
When I resize() the vector I got several error messages,
about some stuff being private int that context.
Is this gcc (3.2) specific or is there a 'official' reason for this?


The C++ iostreams classes are neither CopyConstructable nor Assignable.
So iostream objects cannot reside in objects / containers that require
these properties (e.g., STL containers). For example:

struct X { std::ofstream out; }

X x1, x2;

// Invoke 'X::X(const X&)' (i.e., class X's copy constructor)
X x3(x2); // ERROR -- member 'out' is not copyable

// Invoke 'X::operator=(const X&)'
x1 = x2; // ERROR -- member 'out' is not assignable

--
Jim


All that is true, but the OP has an fstream in a class, and the class was
put in a vector. So the OP can get around this problem if he can define a
copy constructor and assignment operator for his class. Admittedly this
might be difficult.

john
Jul 19 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
by: {AGUT2}=IWIK= | last post by:
Hello all, It's my fisrt post here and I am feeling a little stupid here, so go easy.. :) (Oh, and I've spent _hours_ searching...) I am desperately trying to read in an ASCII...
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...
29
by: Hagen | last post by:
Hello, in a recent thread "speed of vector vs array" I read about the problem of the slow acces by addressing vector elements by indexing, unfortunately I see no workaround in my case. My...
1
by: Macca | last post by:
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...
6
by: Dave Reid | last post by:
Hi everyone... I'm pretty much a newbie C++ user, and I've run into a problem. I'm trying to read in a large text file, and then do manipulations on it. I can read it into a large 2-dimensional...
9
by: Someonekicked | last post by:
In my program, I need to open multiple files, and I wont know till after the program execution how many of them (user will enter that value). So I am using a vector of fstream. I am using fstream...
15
by: arnuld | last post by:
This is the partial-program i wrote, as usual, i ran into problems halfway: /* C++ Primer - 4/e * * Exercise 8.9 * STATEMENT: * write a function to open a file for input and then read...
7
by: D. Susman | last post by:
Hi, In the code snippet below, I am trying to read the contents of a file into a vector. However I can't get it compiled. I am using Sunstudio which compiles C++ using cc. Here is the code:...
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: 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
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.