1

Whenever I use a command as mentioned below, what is the location of the file(in this case, dictionary.txt) in the computer I am taking input from?

int main(){
string line;
fstream file("dictionary.txt");
getline(file, line);}
sidPhoenix
  • 25
  • 1
  • 1
  • 8

4 Answers4

3

Generally, its location is whatever your current directory is at the time you open the file.

However, the ISO standards themselves don't mandate this, it's left up to the implementation. It controls how the contents of the string are interpreted to locate a file.

paxdiablo
  • 854,327
  • 234
  • 1,573
  • 1,953
1

From what i can see, it depends on the system you're running on.

"Specifics about its format and validity depend on the library implementation and running environment."

Usually, on windows, it's first checking relative to the current directory (usually the exec's folder but that can be changed via specific functions) or absolute when you specifically write the full path (ie: c:/ ...).

Edit: check this link for more details: How to use fstream objects with relative path?

Community
  • 1
  • 1
MasterPlanMan
  • 992
  • 7
  • 14
0

This will usually be the same folder as the compiled binary. It can differ depending on the context in which the compiled binary is started though.

Plymouth223
  • 1,905
  • 1
  • 12
  • 22
0

The text file you want to open should exist in the same folder as your whole C++ program unless you specify a path like in this related post: Open file by its full path in C++

Community
  • 1
  • 1