Getcurrentdirectory and setcurrentdirectory are the currentWorking pathInstead of threadsPath.The code below is that there is a write.txt file under the source file, but this file is not in the upper-level path, to illustrate the functions of these two functions.
# Ifndef _ test_h # include <iostream> # include <windows. h> # include <string> # include <stdlib. h> using namespace STD; int main () {char Buf [1000]; int I = 1000; getcurrentdirectory (1000, Buf); // get the current working path string a;. assign (BUF); cout <A <Endl;. append ("\\.. \ "); file * pfile; pfile = fopen (" write.txt "," R "); If (pfile = NULL) cout <" Open failure "<Endl; fclose (pfile); int test = setcurrentdirectory (. c_str (); // set the current path value if (test = 0) cout <"execute failed \ n"; getcurrentdirectory (1000, Buf ); cout <Buf <Endl; pfile = fopen ("write.txt", "R"); If (pfile = NULL) cout <"Open failure" <Endl; else fclose (pfile); Return 0 ;}# endif // _ test_h