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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T05:30:33+00:00 2026-05-20T05:30:33+00:00

Suppose I’m writing a library or a set of tools mytool where a class

  • 0

Suppose I’m writing a library or a set of tools mytool where a class MyTool that other people can use is defined. Suppose I have a directory tree like this:

project
| - program1
    | - main1.cpp
...
| - mytool
    | - mytool.h
    | - mytool.cpp
    | - data.txt

in tool1.cpp I use the external binary huge file data.dat:

ifsteam f("data.txt");

the main1.cpp use mytool, but if mytool.(s)o is linked with main1.o the program can’t find data.dat, for this case I need to change the previous line to:

ifstream f("../mytool/data.txt");

but I can’t know where other people put mytool for example they can have a different directory tree:

project
| - program1
    | - main1.cpp
    | - mytool
        | - tool1.h
        | - tool2.cpp
        | - data.dat

In addition (am I right?) the path depend on where the program is executed.

The only solution I can imagine is to pass to the class contructor MyTool the path of data.dat but I want to keep hidden this file for the user.

  • 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-20T05:30:33+00:00Added an answer on May 20, 2026 at 5:30 am

    You need to know the absolute path of the file, or else the path of the file relative to your working directory. One approach is to have a configuration script which the user runs before compiling your program. The script then hardcodes into your program the relevant path, so the program has the path hardwired in a manner customized for the user.

    Sometimes that’s not an option because you don’t want to distribute the source code, or because you wish to allow the path to change at runtime. Then you can read a configuration file at runtime which says where the file is. But this is just a layer of abstraction: you still need to know where that configuration file is. You might, for example, ask the system where the user’s personal directory is, and then find the file there at that directory. This is a sort of mix between compile-time and runtime computation of the path.

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

Sidebar

Related Questions

Suppose I have a static method of my class that returns an object of
Suppose I have a class Baz that inherits from classes Foo and Bar ,
Suppose I have defined the symbolic function x -> f(x) in Matlab. How can
Suppose I have a vertical menu that is coded like this: <ul class=sub-menu> <li
Suppose i have an XML file, that i use as local database, like this):
Suppose I have a class whose constructor spawns a thread that deletes the object:
Suppose I have a pure virtual method in the base interface that returns to
Suppose I have a simple model, such as Record: @Model public class Record {
Suppose I have a process that is updating a record and encounters a record
Suppose I have a base class as following: class User: user_types = [] def

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.