Relative Filename Problem

T

Tanuki

Hi:

I have a problem regarding filenames in Visual C++.

I would like to read from files using relative filenames instead of
absolute filenames. I have tried using the following

fname = .\\<data directory>>\\<<file1>>

I have no problem when executing from within the IDE (i.e. pressing
CTRL+F5) but when I run the executable (i.e. <prog.exe> ), the file
cannot be found.

When I tried to change it to
fname = ../<data directory>>/<<file1>>
the executable can work but this time round, executing from the IDE
will render file not found problem.

I know this may be trivial to experts here but sincerely appreciate
any help. Thank you.
 
J

Jack Klein

Hi:

I have a problem regarding filenames in Visual C++.

Then you need to ask about it in a group that supports your
implementation, such as or
one of Microsoft's support groups in the family.
I would like to read from files using relative filenames instead of
absolute filenames. I have tried using the following

fname = .\\<data directory>>\\<<file1>>

I have no problem when executing from within the IDE (i.e. pressing
CTRL+F5) but when I run the executable (i.e. <prog.exe> ), the file
cannot be found.

When I tried to change it to
fname = ../<data directory>>/<<file1>>
the executable can work but this time round, executing from the IDE
will render file not found problem.

I know this may be trivial to experts here but sincerely appreciate
any help. Thank you.

The C++ language defines file access functions that accept a C style
string for dealing with fstream and FILE * streams. It does not
specify the content of those strings, or how they are interpreted by
the implementation's file system.

The details of how Windows maps strings into paths and file names is a
Windows specific detail, not one specified by the language.

--
Jack Klein
Home: http://JK-Technology.Com
FAQs for
comp.lang.c http://www.eskimo.com/~scs/C-faq/top.html
comp.lang.c++ http://www.parashift.com/c++-faq-lite/
alt.comp.lang.learn.c-c++ ftp://snurse-l.org/pub/acllc-c++/faq
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,157
Messages
2,570,879
Members
47,413
Latest member
KeiraLight

Latest Threads

Top