> But not working..
What is not working? How did you use the command?
> Can U provide small code...
Yup , it took me about 10 seconds on google
Nick Evan
Not a Llama
10,112 posts since Oct 2006
Reputation Points: 4,142
Solved Threads: 403
Microsoft compilers do not use unistd.h -- that's for *nix. And Microsoft put an underscore in front of the name, so its _getcwd(). . The link contains example code too.
Ancient Dragon
Retired & Loving It
30,049 posts since Aug 2005
Reputation Points: 5,662
Solved Threads: 2,343
Microsoft compilers do not use unistd.h -- that's for *nix. And Microsoft put an underscore in front of the name, so its _getcwd(). . The link contains example code too.
Hmm, I've tried the code on my Windows Machine with VC2005 and it compiles fine ? Not even warnings or whatever..
Nick Evan
Not a Llama
10,112 posts since Oct 2006
Reputation Points: 4,142
Solved Threads: 403
use setenv() , but it only works for the current process. When that process ends the new environment variable is reset back to its original state. The only way to make it permanent in the system is to change it via control panel.
Ancient Dragon
Retired & Loving It
30,049 posts since Aug 2005
Reputation Points: 5,662
Solved Threads: 2,343
Now what i want is to add string to this path.
You could use a stringstream to add a string to a char[]. It would look something like this (untested):
#include <sstream>
#include <iostream>
using namespace std;
int main(void)
{
char path[] = "c:\\test\\";
string file = "default.txt";
stringstream complete;
complete << path << file;
cout << complete.str() << endl;
cin.get();
return 0;
}
There are alot of other ways to do this.
Nick Evan
Not a Llama
10,112 posts since Oct 2006
Reputation Points: 4,142
Solved Threads: 403
Some remarks to the previous post:
1. Alas, argv[0] IS NOT a path of exe module.
The C standard (5.1.2.2.1 Program Startup):If the value of argc is greater than zero, the string pointed to by argv[0] represents the program name; argv[0][0] shall be the null character if the program name is not available from the host environment.
Theprogram name is not the same thing as an exe path!
2. The exe directory does not bear a relation to the current working directory...
3. No platform-independent methods to get the current working directory. The getcwd function is not C and C++ standard library function...
ArkM
Postaholic
2,001 posts since Jul 2008
Reputation Points: 1,234
Solved Threads: 348
Is your reference the c0x standard? It's not even implemented yet... It's called the c0x standard because it is meant to be released some year this decade (now it must be 2009). For most people, portability between Windows, MacOS, and Linux are enough. On those OSes, getcwd() works and argv[0] works (at least with GCC) to give you the full command line call to your executable. Don't argue until you try the above code... What else is the "program name" except what the OS sees (i.e. what it needs to know in order to run your program)? You'll be hard-pressed to find a counter-example to this functionality, though I welcome one.
Alas, all your statements are wrong. It was a quote from the CURRENT Standard (was adopted 10 years ago). I never said that getcwd function does not work IF IT'S IMPLEMENTED, but it's not standard function - that's all. MS VC++ exe module gets full path in argv[0] if it started from IDE but argv[0] contains file name only (without path and extension) when it started from command line window.
It's funny ;)...
ArkM
Postaholic
2,001 posts since Jul 2008
Reputation Points: 1,234
Solved Threads: 348