E
E
Eugene2014-11-11 22:18:36
C++ / C#
Eugene, 2014-11-11 22:18:36

How to allow file input in the program in MVS?

How to allow the program to read the file stream in MVS during debugging?
Such a program does not work correctly (does not open the file). If you do not run from MVS, everything works fine.

char a;
  ifstream creat;
  creat.open("1.txt");
  while (true)
  {
    //creat >> a;
    creat.get(a);
    if (!creat.eof())
      cout << (int)a<<' ';
    else
      break;
  }
  creat.close();

Answer the question

In order to leave comments, you need to log in

2 answer(s)
T
Teivaz, 2014-11-12
@Jek_Rock

The problem is in the working directory.
In Project -> Properties -> Debugging -> Working Directory we set $(TargetDir)
And the current directory at startup will be the one where the executable file is located. Or you can use an absolute path.

G
GavriKos, 2014-11-11
@GavriKos

It is necessary to look in the VS project settings for the working directory of the program. Most likely there is no 1.txt file in it. And in the code itself, it will not hurt to insert a check on the subject "whether the file has opened".

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question