Welcome to the MacNN Forums.

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

You are here: MacNN Forums > Software - Troubleshooting and Discussion > Developer Center > fstream problem

fstream problem
Thread Tools
Forum Regular
Join Date: Oct 2000
Location: Portland, OR USA
Status: Offline
Reply With Quote
Feb 4, 2003, 05:58 PM
 
I'm trying to use an fstream in C++ and I keep getting the following error:


/usr/include/gcc/darwin/2.95.2/g++/streambuf.h:132: `ios::ios(const ios &' is private within this context
The following will cause the error:
Code:
#include <iostream> #include <fstream> #define BUFFER_SIZE 256 int main(int argc, char *argv[]) { char buf[BUFFER_SIZE]; ifstream fin = ifstream("foo.cpp"); while (!fin.eof()) { fin.read(buf, BUFFER_SIZE); cout.write(buf, fin.gcount()); } fin.close(); return 0; }
I am running OS X 10.1.5 on a B&W @ 350MHz if that helps.
     
Mac Elite
Join Date: Sep 2000
Location: Tempe, AZ
Status: Offline
Reply With Quote
Feb 4, 2003, 10:27 PM
 
Does it work if you make your constructor look like this?
Code:
ifstream fin("foo.cpp");
I've had problems (can't remember what they were) with fstream on OS X. Whatever they were, they made me start using code like the following on a regular basis:
Code:
ifstream fin = new ifstream("foo.cpp"); // do something delete fin;
Geekspiff - generating spiffdiddlee software since before you began paying attention.
     
Forum Regular
Join Date: Oct 2000
Location: Portland, OR USA
Status: Offline
Reply With Quote
Feb 5, 2003, 03:30 AM
 
Thanks, the direct construction works.
     
   
Thread Tools
Forum Links
Forum Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Top
Privacy Policy
All times are GMT -5. The time now is 08:45 PM.
All contents of these forums © 1995-2011 MacNN. All rights reserved.
Branding + Design: www.gesamtbild.com
vBulletin v.3.8.7 © 2000-2011, Jelsoft Enterprises Ltd., Content Relevant URLs by vBSEO 3.3.2