So this is a simple C++ program for reading a file and displaying its contents. My directory structure is as follows
Project Directory | Data___ | | | data.txt | program1.cpp
and The program:
#include <iostream>
#include <fstream>
using namespace std;
int main () {
char char1;
fstream data; // Because I wanna to write to this file later.
data.open("../Data/data.txt",ios::out | ios::in);
if (data.is_open()) {
for (int i = 0; !data.eof(); ++i) {
data.get(char1);
cout << char1 << endl;
}
data.close();
}
return 0;
}
So currently my program works fine... However when I use:
data.open("Data/data.txt",ios::out | ios::in);
The program doesn't work. Why is this so? Ideally the above mentioned code piece should work since the Data folder is in the same directory as my cpp file.
data.open("../Data/data.txt",ios::out | ios::in);
By using 2 dots we are going back a directory and the Data folder isn't there.
Then why is the program working using the 2 dots?