LinuxQuestions.org
View the Most Wanted LQ Wiki articles.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 12-14-2006, 10:01 PM   #1
m_lp_ql_m
Member
 
Registered: Dec 2003
Location: So Cal
Distribution: Debian Etch
Posts: 59

Rep: Reputation: 15
C++ ios::nocreate ?


I'm trying to
Code:
outfile.open("output.dat", ios::nocreate);
, but the compiler gives me
Code:
error: 'nocreate' is not a member of 'std::ios'
The book I'm studying out of is a 2002 edition, but all the Googling seems to imply that ios::nocreate is deprecated. Is this true?
 
Old 12-15-2006, 12:19 AM   #2
asgeirss
Member
 
Registered: Aug 2003
Location: Vancouver, Canada
Distribution: RH, SL
Posts: 37

Rep: Reputation: 15
As far as I know (not an expert) the C++ Standard Template library was either non-existent, or in its infancy in 2002, so it is not surprising that your examples no longer are supported by ISO C++. A quick search for the ios header shows no member named nocreate.

Depending on what class 'outfile' is, you should be able to look in the header file for that class and see what the proper syntax is for .open options.

- Dave
 
Old 12-15-2006, 09:50 PM   #3
m_lp_ql_m
Member
 
Registered: Dec 2003
Location: So Cal
Distribution: Debian Etch
Posts: 59

Original Poster
Rep: Reputation: 15
So if one does not want to create a new file if one does not exist, what does one do?
 
Old 12-16-2006, 02:16 AM   #4
adament
LQ Newbie
 
Registered: Apr 2006
Posts: 3

Rep: Reputation: 0
There's no portable clean approach with the standard library that I can think of. If you want to do it solely with the standard library one approach could be to try to open the file for reading and only if this succeeds open it for writing. However as I said it isn't very clean.

If it only has to work on Posix compatible systems have a look at the stat function http://www.gnu.org/software/libc/man...ttributes.html you can then use this function to check if the file exists.

If you want to cross platform have a look at the Boost filesystem library, it provides a nice exists function. http://www.boost.org/
 
Old 12-16-2006, 07:17 AM   #5
Tux-Slack
Member
 
Registered: Nov 2006
Location: Slovenia
Distribution: Slackware 13.37
Posts: 511

Rep: Reputation: 36
try it like this:
dat.open("data.dtc",ios::in|ios::nocreate);

be sure to:
#include <fstream.h>

and to:
fstream dat;


it works like this for me under C++ v6.0
 
Old 12-17-2006, 05:21 AM   #6
adament
LQ Newbie
 
Registered: Apr 2006
Posts: 3

Rep: Reputation: 0
The problem with ios::nocreate is that it isn't in the C++ standard and therefore isn't supported by g++.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting 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 Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Cisco IOS graciejj_82 Linux - Networking 2 08-01-2006 07:42 AM
IOS cisco emulator gabsik Linux - Software 1 06-07-2006 06:13 PM
c++ ios::app and ios::ate gearoid_murphy Programming 6 04-08-2006 07:01 AM
has anyone had trouble with their IOS anubis65656 Linux - Networking 1 02-23-2006 09:49 AM
Ios pk21 Linux - Security 3 08-08-2003 11:13 PM


All times are GMT -5. The time now is 04:13 AM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration