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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T02:26:32+00:00 2026-05-23T02:26:32+00:00

This is a main file that I am using to test methods before I

  • 0

This is a main file that I am using to test methods before I implement them. I am trying to get the list of all files in a directory, write them to a txt file (It works fine until here), then read the file names from that text file.

using namespace std;

string sysCall = "", location = "~/Documents/filenames.txt";
string temp = "";
sysCall = "ls / > "+location;
system(sysCall.c_str());

ifstream allfiles(location.c_str());
allfiles.good();
getline(allfiles, temp);
cout<<temp<<endl;  //At this point, the value of temp is equal to ""

return -1;

After the program runs, no text has been outputted. From what I’ve read in other peoples’ questions, this should work (but obviously doesn’t). What am I doing wrong here?

EDIT: allfiles.good() returns false, but I don’t understand why it would return that…

  • 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-23T02:26:33+00:00Added an answer on May 23, 2026 at 2:26 am

    ifstream allfiles("~/Documents/filenames.txt"); doesn’t do what you think it does. The tilde ~ character is not part of the filename — it is a special character interpreted by some shells. You need the entire path, with no ~ or $ characters in it.

    Try setting location to "/tmp/filenames.txt", or just "filenames.txt".

    Also, if Boost.Filesystem is available to you, you could use a directory_iterator instead of invoking /bin/ls.

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

Sidebar

Related Questions

I have a code that looks like this: int main () { fstream file;
I have a system that runs like this: main.exe runs sub.exe runs sub2.exe and
I'm currently trying to write a multiple-file Python (2.6.5) game using PyGame. The problem
This example demonstrates using Scanner to read a file line by line (it does
I have a struct defined in a header file with three other files that
I have a number of Eclipse projects that are all using classes from a
Exception in thread main java.lang.NullPointerException at com.hibernate.UserDAO.findAll(UserDAO.java:154) at test.main(test.java:12) I am getting this error
I have this class: class View(object): def main_page(self, extra_placeholders = None): file = '/media/Shared/sites/www/subdomains/pypular/static/layout.tmpl'
The situation is like this : Main project A. and a class library B.
My program is like this ( main.c ): #include <stdlib.h> #include <stdio.h> void main(){

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.