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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T06:40:15+00:00 2026-05-23T06:40:15+00:00

I am just trying to open this file and use the getline function to

  • 0

I am just trying to open this file and use the getline function to read from the file but I cant seem to figure out why it is not working. I have stepped through it many times and the fileOpen variable is being loaded correctly with the file im trying to open, so Im unsure on why it wont open, to use getline with it. I would just like to be able to read through the file with getline, all of this is done in a recursive function to eventually read through all the files in directories. Let me know if you need more information on what exactly im doing.

string line;
ifstream file;
string fileOpen;
bf::directory_iterator dirIter ( fullPath ); //fullPath is type bf::path, passed into the function
fileOpen = (dirIter->path().filename());

file.open(fileOpen);
getline(file, line);
  • 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-05-23T06:40:16+00:00Added an answer on May 23, 2026 at 6:40 am

    The path::filename function returns the base filename. If you have a path of “foo\bar.txt”, path::filename will return “bar.txt”. So unless “foo\” is in the current directory, the file probably doesn’t exist.

    What you’re more likely looking for is this:

    file.open(dirIter->path().native());
    

    Or, you can use the boost::filesystem iostream types:

    #include <boost/filesystem/fstream>
    
    bf::ifstream file;
    bf::directory_iterator dirIter ( fullPath ); //fullPath is type bf::path, passed into the function
    file.open(dirIter->path());
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to use regex to parse out some lines from text read
I've been trying to figure out how to use jsonp in my situation, but
just trying to test for equality in this piece of code, but getting a
Ok, I'm trying to figure out which way would be faster to read a
I'm trying to use file_get_contents but it tells me failed to open stream. My
I am just trying to write a code to open file by clicking a
I am trying to read from a text file and tokenize the input. I
I'm trying to use a dialog box to open a file in my program.
Just trying to get my head around Generics by reading this enlightening article by
Just trying to get my head round Spring and figuring out how I wire

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.