What is a cross-platform way to get the current directory?
Posted
by rubenvb
on Stack Overflow
See other posts from Stack Overflow
or by rubenvb
Published on 2010-05-19T19:22:26Z
Indexed on
2010/05/19
19:40 UTC
Read the original article
Hit count: 183
I need a cross-platform way to get the current working directory (yes, getcwd does what I want). I thought this might do the trick:
#ifdef _WIN32
#include <direct.h>
#define getcwd _getcwd // stupid MSFT "deprecation" warning
#elif
#include <unistd.h>
#endif
#include <string>
#include <iostream>
using namespace std;
int main()
{
string s_cwd(getcwd(NULL,0));
cout << "CWD is: " << s_cwd << endl;
}
I got this reading:
There should be no memory leaks, and is should work on a Mac as well, correct?
© Stack Overflow or respective owner