P
P
Pavel2015-12-06 19:26:57
C++ / C#
Pavel, 2015-12-06 19:26:57

Why doesn't Visual Studio open the file when debugging?

int main()
{
  ifstream fileList("paths.txt");
  vector<string> paths; 
  string path;
  int i = 0;
  if(fileList.is_open())
  {
    while (!fileList.eof())
    {
      getline(fileList, path);
      cout << path<<endl;
      paths.push_back(path);
      i++;
    }
    fileList.close();
  }
  system("pause");
    return 0;
}

A simple example is to open a file, read its contents and write it to an array. When you run exe from the debug folder, it outputs the contents of the file to the console, but does not open the file from the studio during debugging. What could be the error?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexander Latyshev, 2015-12-06
@rusbaron

By default, when starting a project from the studio, the current directory is the project directory. Therefore, during debugging, the program does not find the file you need (which is located in another directory - in the debug folder. This behavior can be changed in the project settings:
2cf86141b4614fda889c669d8db45009.PNG

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question