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 9042629
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T10:32:39+00:00 2026-06-16T10:32:39+00:00

I have a C++ document in which I need to open a file. I’m

  • 0

I have a C++ document in which I need to open a file. I’m not using a relative path to refer to my file. I’m currently using the full file path on my hard drive, although later I’ll switch to just using the current directory. In any case, I know for a FACT that this file is being referred to correctly and is open-able, because I’ve performed stat() on the filename and it returns all of the correct info about the file. Here’s the basic process that’s happening:

string fName = "C:\\Users\\[user]\\Downloads\\file.DAT";
ifstream inFile;
inFile.open(fName);

struct _stat buf;                        // I put these lines here to test that
int result = _stat(fName.c_str(), &buf); // the file is being referred-to right

inFile >> levelnumber;
if(inFile.fail())  // inFile.fail() keeps evaluating to TRUE
    ThrowError("Corrupt or inaccesible .DAT file."); // I wrote ThrowError

Anyway, inFile.fail() keeps evaluating to true, even though the file is definitely being referred-to correctly (that’s what the call to _stat() checks).

What am I doing wrong? 😛

  • 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-16T10:32:40+00:00Added an answer on June 16, 2026 at 10:32 am

    Your test doesn’t tell you whether the file could be opened. What your test tells you is that either the file couldn’t be opened or levelnumber couldn’t be read. To test if your file was opened, you can check the file right after the call to open(). If the file is indeed readable, it should convert to true:

    std::ifstream inFile(fName);
    if (!inFile) {
        std::cerr << "failed to open '" << fName << "' for reading\n";
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

simple thing which I need to do is, that I have a pdf document
I have the following jQuery which I need adapting: $(document).ready(function(){ $(.rss-popup a).hover(function() { $(this).next(em).stop(true,
I have an type of document which users should not be able to read
How can I determine the path of the currently open document in an OpenOffice
I have a lovely AppleScript droplet which performs OCR of a PDF file using
We have a requirement, in which we need to create dynamic word document and
I have a user document which has a group field. This field is an
I have an xml document which consists of a number of the following: -
I have an XML document which contains nodes like following:- <a class=custom>test</a> <a class=xyz></a>
I have an XML document which looks something like this: <meadinkent> <record> <comp_div>MENSWEAR</comp_div> <sty_ret_type>ACCESSORIES</sty_ret_type>

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.