Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C++ Visual Studio Current Working Directory

I have a similar problem to this: Current working directory is visual studio directory

Except that I am working with a C++ project in Visual Studio. Any suggestions?

For example if I try the solution in the following post: GetCurrentDirectory for startup App. c++

I get this:

"C:\PROGRAM FILES (X86)\MICROSOFT VISUAL STUDIO 11.0\COMMON7\IDE"

But I want it to be the Debug folder under my project/solution folders.

like image 794
dtmland Avatar asked Oct 30 '13 18:10

dtmland


1 Answers

Using the _fullpath command allowed me to extract the current directory. For example you can modify the example code on the linked page :

#include <stdio.h>
#include <conio.h>
#include <stdlib.h>
#include <direct.h>

void PrintFullPath( char * partialPath )
{
   char full[_MAX_PATH];
   if( _fullpath( full, partialPath, _MAX_PATH ) != NULL )
      printf( "Full path is: %s\n", full );
   else
      printf( "Invalid path\n" );
}

int main( void )
{
   // Get current directory
   PrintFullPath( ".\\" );
}
like image 129
dtmland Avatar answered Oct 27 '22 01:10

dtmland