Hello, I know how to read from a text file that i have saved in the directory where i am compiling from but how do i read or write from a file that is in another directory on my PC?
Hello, I know how to read from a text file that i have saved in the directory where i am compiling from but how do i read or write from a file that is in another directory on my PC?
use "C:\\<path goes here>" before the path name. So for example:
your program is running in
C:\MyProgram\
Normally when you'd do file.open("file.txt"); it would open it like so: C:\MyProgram\file.txt
However, when you attach a drive to the beginning, like so: file.open("C:\\file.txt"); it will actually search for the file AT C:\file.txt
There are also ways to look in the "parent" folder by using .\ or ..\ before the filename. This is useful if you have hierarchy system of files that you want to scan through.
Also, if you dont' already know, look in to the GetCurrentDirectory and SetCurrentDirectory functions found in windows.h, they are very useful when it comes to accessing files.