C ++ gets the current path

xiaoxiao2021-03-06  40

C gets the current path

Author: liang bo

Brianliangx@hotmail.com

1. // The following code comes from the 9CBS 2004 VC programming experience. Respect the copyright, in order to revitalize China Software

{

Cstring strpath;

GetCurrentDirectory (max_path, strpath.getbuffer);

StrPath.releaseBuffer ();

Return strpath;

}

2. // The following code is from TZ MFC.NET Primer 1.01, access www.appTemplate.com to get more code and information

// Respect the copyright, in order to revitalize China software

CString Cpropertygridsampleapp :: getCurrWorkingDir ()

{

Cstring strpath;

Tchar szfull [_max_path];

Tchar szdrive [_max_drive];

Tchar Szdir [_MAX_DIR];

:: GetModuleFileName (Null, Szfull, Sizeof (Szfull) / Sizeof (Tchar);

_TSPLitpath (SZFULL, SZDRIVE, SZDIR, NULL, NULL);

_TCSCPY (SZFULL, SZDRIVE);

_TCSCAT (SZFULL, SZDIR);

StrPath = CString (SZFULL);

Return strpath;

}

Using the first code can get the application running when the application is running. However, because when using Microsoft Visual Studio.net, the real host is IDE, so the current directory is the directory where the project is located, not the debug or release directory, which requires the development of the developer. The second section can be dynamically resolved. And add Unicode support (TCHAR).

转载请注明原文地址:https://www.9cbs.com/read-63626.html

New Post(0)