0
Inserting path to open file
Here is my code #include <string> #include <fstream> using namespace std; string Path = "D:\\DevPrograms\\Test"; //This a the folder containing a test.txt file int main (){ ofstream File; File.open ("What should I enter here to use the Path var above, and then add file name 'test.txt' to open it") }
2 Antworten
+ 2
That is sort of what I have currently.
path = "D:\\ DevPrograms\\Test\\test.txt"
and it works The problem is you have to have a var for each file to define a certain path. Thus is there a way to select a folder with a bunch of files in it, and then select a certain file when you go to open it.
For example:
Path = D:\\...
file1.open ((Path+"Test1.txt"))
file2.open ((Path+"Test2.txt"))
Edit: I figured it out.
string Path = D:\\DevPrograms\\Test;
int main ()
{
fstream File1;
fstream File2;
File1.open((Path + "\\Test1.txt"))
File2.open((Path + "\\Test2.txt"))
}
0
Try File.open("D:\\DevPrograms\\Test.txt")