Hello,
I am writing a c++ program that stores some values in a config located
in it's directory.
is there a way in c++ to get the full path of the running program so I
can open the file not relative to where I run it from but where it is
located?
Thanks
Jay 5 1920
Jay wrote: Hello, I am writing a c++ program that stores some values in a config located in it's directory. is there a way in c++ to get the full path of the running program so I can open the file not relative to where I run it from but where it is located?
Thanks Jay
The C++ language knows nothing of such things; it's inherently platform
specific -- and sometimes not even (reliably) possible.
Your best bet is to try a platform specific forum or find another way to
solve the problem.
Sorry, but HTH,
--ag
--
Artie Gold -- Austin, Texas http://goldsays.blogspot.com (new post 8/5) http://www.cafepress.com/goldsays
"If you have nothing to hide, you're not trying!"
Jay wrote: Hello, I am writing a c++ program that stores some values in a config located in it's directory. is there a way in c++ to get the full path of the running program so I can open the file not relative to where I run it from but where it is located?
Thanks Jay
You might be able to use the Boost Filesystem library: http://boost.org/libs/filesystem/doc/index.htm
Cheers! --M
"Jay" <Co******@gmail .com> wrote in message
news:11******** *************@o 13g2000cwo.goog legroups.com... Hello, I am writing a c++ program that stores some values in a config located in it's directory. is there a way in c++ to get the full path of the running program so I can open the file not relative to where I run it from but where it is located?
Some implementations , e.g. for Windows, provide the full
path of the executable as main()'s argv[0]. But this is
not guaranteed by the language.
-Mike
Mike Wahler <mk******@mkwah ler.net> wrote: "Jay" <Co******@gmail .com> wrote in message news:11******** *************@o 13g2000cwo.goog legroups.com... Hello, I am writing a c++ program that stores some values in a config located in it's directory. is there a way in c++ to get the full path of the running program so I can open the file not relative to where I run it from but where it is located?
Some implementations , e.g. for Windows, provide the full path of the executable as main()'s argv[0]. But this is not guaranteed by the language.
True that it is not guaranteed by the language. However, I think your
wording may be a little misleading: when I first read it, I interpreted
your statement as meaning that all implementations on Windows will
provide the full executable path. For example,
#include <iostream>
int main(int argc, char* argv[])
{
std::cout << "I am: " << argv[0] << '\n';
return 0;
}
only prints whatever I used to invoke the program. If I am in the same
directory as the program, I get:
I am: test
and if I move one directory down in the hierarchy but invoke the program
in the parent directory, I get:
I am: ..\test
--
Marcus Kwok
"Marcus Kwok" <ri******@gehen nom.net> wrote in message
news:do******** **@news-int2.gatech.edu ... Mike Wahler <mk******@mkwah ler.net> wrote: "Jay" <Co******@gmail .com> wrote in message news:11******** *************@o 13g2000cwo.goog legroups.com... Hello, I am writing a c++ program that stores some values in a config located in it's directory. is there a way in c++ to get the full path of the running program so I can open the file not relative to where I run it from but where it is located? Some implementations , e.g. for Windows, provide the full path of the executable as main()'s argv[0]. But this is not guaranteed by the language.
True that it is not guaranteed by the language. However, I think your wording may be a little misleading: when I first read it, I interpreted your statement as meaning that all implementations on Windows
See above, "Some implementations "
will provide the full executable path. For example,
#include <iostream>
int main(int argc, char* argv[]) { std::cout << "I am: " << argv[0] << '\n';
return 0; }
only prints whatever I used to invoke the program. If I am in the same directory as the program, I get:
I am: test
and if I move one directory down in the hierarchy but invoke the program in the parent directory, I get:
I am: ..\test
This all depends upon the compiler and platform. Sorry if I wasn't
clear.
-Mike This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Kevin Thorpe |
last post by:
I don't suppose anyone knows of a script/program to try and identify
where variables are used assuming register_globals is on? I'm trying to
fix an application and would rather not turn it on as there are several
applications on the server.
I'm thinking of something which can identify use of variables (right
hand side of assignments) before definition (left hand side of assignments).
Any pointers?
|
by: Mike |
last post by:
I am sure that I am making a simple boneheaded mistake and I would
appreciate your help in spotting in. I have just installed
apache_2.0.53-win32-x86-no_ssl.exe
php-5.0.3-Win32.zip
Smarty-2.6.7.tar.gz
on a system running WindowsXP SP2.
Apache and PHP tested out fine. After adding Smarty, I ran the
following http://localhost/testphp.php
|
by: Hal Vaughan |
last post by:
I want to have a config file for my program, which means I need to know
where the config file is. If I type:
java myclass
and it runs myclass.class, is there any way to obtain the location of the
file myclass.class? Will this work if it's run from a relative path, like:
java ../progs/myclass
|
by: Todd Johnson |
last post by:
Hey,
I have been working on a program that stores
information for each user in a subdirectory of the
directory in which the script is run. So if my script
is in /home/someuser/myprogram, the config files and
such are in /home/someuser/myprogram/config. Now if I
invoke the interpreter from the same directory as the
script is in I can load and save the files because cwd
points to that directory(I used cwd to get the path
|
by: Rick Strahl [MVP] |
last post by:
Hi all,
I'm building an app that uses the ASP.Net runtime...
One problem I've run into is that pages running inside of the runtime are
not finding DLLs in the GAC. In fact, if I look at the debug trace of the
search path it searches the bin directory and Temporary ASP files but not
the GAC.
A simple example I used was trying to load System.Windows.Forms. If I add a
| |
by: Sigmathaar |
last post by:
Hi, while making an XML parser for the creation of an entire directory
list I got this problem and I'm having trouble solving it. The program
(not yet written) goes through an XML Schema Instance to create some
directories (about 5000).
While creating the directories the XML file that I'm parsing is
alphabetically ordered not hierarchically and I can't allow the program
to stock the path names for each brach on the directory tree.
The...
|
by: Rich |
last post by:
I am trying to use unmanaged DLLs within managed code. My approach is
to create a managed DLL with wrapper functions for my unmanaged
functions. The unmanaged functions come from an unmanaged DLL.
I can successfully build my managed DLL and use it from managed code.
However, at runtime the code cannot find the unmanaged DLL. I've tried
putting the unmanaged DLL in the same directory as the code is running
from, in C:\Windows\System32,...
|
by: Joshua J. Kugler |
last post by:
So, I have:
ModTest
__init__.py
AModule.py
BModule.py
CModule.py
All works fine. However, when I import ModTest, I would like it to discover
and store the names of the modules beneath it, and construct a list, say
|
by: Nepomuk |
last post by:
Hi!
I'm trying to run an external Program with
Process p = Runtime.getRuntime().exec("/bin/sh -c \"/bin/gzip -c /home/user/workspace/TarGz/pics.tar > pics.tar.gz\"");
CleanStream cleanError = new CleanStream(p.getErrorStream(), "ERROR");
CleanStream cleanOutput = new CleanStream(p.getInputStream(), "OUTPUT");
clearError.start();
clearOutput.start();
p.waitFor();
under Linux.
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |