Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8619045
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T06:15:02+00:00 2026-06-12T06:15:02+00:00

I am developing in C++ using NetBeans 6.9 on Ubuntu 11.04. I have declared

  • 0

I am developing in C++ using NetBeans 6.9 on Ubuntu 11.04. I have declared the input and output file name strings and file streams thus

ifstream    fpInputFile, fpOutputFile;
string  inputFileName="", outputFileName="";

The input file name is assigned the name of an existing file as an input argument to the application. The output file name is given the same as the input name except that “_output” is inserted before the final period. So the output is written to the same directory as the input is located. Also I start netbeans with

su netbeans

so the IDE has root privileges to the directory. I try to open the files, and check whether they are opened thus.

fpInputFile.open(inputFileName.c_str(), ifstream::in);
fpOutputFile.open(outputFileName.c_str(), ifstream::out);
if (!(fpInputFile.is_open())) throw ERROR_OPENING_FILE;
if (!(fpOutputFile.is_open())) throw ERROR_OPENING_FILE;

The input file opens successfully but the output file does not.

Any help in determining why the output file is not opening for writing would be most appreciated.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T06:15:04+00:00Added an answer on June 12, 2026 at 6:15 am

    The obvious problem is that you probably meant to open the file using a std::ofstream rather than an std::ifstream. This helps with actually writing to the stream although there are ways to write to an std::ifstream as long as it is opened for reading. For example, you could use the std::streambuf interface directly or use the std::streambuf to construct and std::ostream.

    The more interesting question is: why isn’t the file opened for writing when std::ios_base::in | std::ios_base::out is used for the open mode? std::ifstream automatically adds std::ios_base::in. It turns out, that the mode std::ios_base::in | std::ios_base::out doesn’t create a file but it would successfully open an existing file. If you really want use an std::ifstream to open a file for output which potentially doesn’t exist you would need to use either std::ios_base::out | std::ios_base::trunc or std::ios_base::out | std::ios_base::app:

    • the former would force the file to be created or truncated if it exists
    • the latter would force writes to append to the file in all cases

    My personal guess is, however, that you are best off just using std::ofstream or, if you want to open the file for both reading and writing std::fstream (which, however, would also need to have std::ios_base::trunc or std::ios_base::app added to create a file if none exists).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have been developing a Java program in Netbeans/Ubuntu 12.04 using OpenJdk. I have
I am using Netbeans 6.9 on Ubuntu 11.04. I am developing a console op.and
I have a simple application using netbeans for developing and maven for building et
I am developing fot Android using NetBeans. I have moved from Eclipse, where I
I am developing a C++ application using NetBeans 6.9 on Ubuntu 11.04. I am
I am developing a web application using JSF on Netbeans 7.0. I have created
I am developing a Lift application using Netbeans and I have everything working apart
I've been developing Java with Netbeans and have been using the Run command on
I am using netbeans for developing java dextop application,I have created a JFilechooser which
I am developing using Netbeans 7.1. In my jasper report I have subreport in

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.