Cmd ausgabe in ner variable speichern?
-
Hi
ich hab ne frage: Ich möchte mit system("cd"); den pfad des programms abfragen und diesen in einer Variable speichern. Wie geht das?
MFG Yazoo
-
nimm GetCurrentDirectory
-
wie benutzt man denn GetCurrentDirectory?
-
-
Dieser Thread wurde von Moderator/in HumeSikkins aus dem Forum C++ in das Forum WinAPI verschoben.
Im Zweifelsfall bitte auch folgende Hinweise beachten:
C/C++ Forum :: FAQ - Sonstiges :: Wohin mit meiner Frage?Dieses Posting wurde automatisch erzeugt.
-
thx der inhalt der variable ist nun: "C:\***\Ordner" ...ich möchte noch was an die Variable dranhängen und zwar "\test.txt" wie mach ich das?
-
Verwende "std::string", dann einfach mit "+="
-
Jochen, du hältst dich heute mal wieder extrem kurz...

C++:
#include <string> #include <tchar.h> #include <windows.h> int main( ) { typedef std::basic_string< TCHAR > tstring; std::size_t size( 0 ); size = GetCurrentDirectory( size, 0 ); TCHAR *buffer = new TCHAR[ size ]; GetCurrentDirectory( size, buffer ); tstring current_directory( buffer ); delete[ ] buffer; current_directory += _T( "\\Sonstwas" ); MessageBox( 0, current_directory.c_str( ), _T( "Current Directory" ), MB_OK ); }C
#include <stdlib.h> #include <tchar.h> #include <windows.h> int main( ) { const TCHAR str_to_append[ ] = _T( "\\Sonstwas" ); size_t size = 0; TCHAR *current_directory = 0, *tmp = 0; size = GetCurrentDirectory( size, 0 ); if( !( current_directory = malloc( size * sizeof( TCHAR ) ) ) ) { MessageBox( 0, _T( "Not enough memory!" ), _T( "Error:" ), MB_OK | MB_ICONEXCLAMATION ); exit( EXIT_FAILURE ); } GetCurrentDirectory( size, current_directory ); if( !( tmp = realloc( current_directory, ( size * sizeof( TCHAR ) ) + sizeof( str_to_append ) ) ) ) { MessageBox( 0, _T( "Not enough memory!" ), _T( "Error:" ), MB_OK | MB_ICONEXCLAMATION ); free( current_directory ); exit( EXIT_FAILURE ); } current_directory = tmp; _tcscat( current_directory, str_to_append ); MessageBox( 0, current_directory, _T( "Current Directory:" ), MB_OK ); }greetz, Swordfish