Answer the question
In order to leave comments, you need to log in
How to correctly read the file when compiling?
When compiling the project, the program does not read the "text.txt" file, although the path is correct. The if (!fin) option always passes. How to fix?
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
int main() {
string str;
cout << "Vvedite slovo" << endl;
cin >> str;
ifstream fin("D:\\Program files\\VisualStudio\\Projects\\Dliya DZ\\Debug\\text.txt");
if (!fin) {
cout << "Fail";
system("pause");
return 0;
}
...
Answer the question
In order to leave comments, you need to log in
When compilingalready when running
ifstream ifs("text.txt");
I think that you should either rename the file so that there is no space in the full file name, or add enclosing double quotes to the string (do not forget to escape them).
Try changing the slashes from backticks to regular slashes (from \\ to //)
I tried it myself: it finds through spaces and such slashes - "\\".
There is only one conclusion - your path is wrong. In such cases, I use the button "copy names with paths to clipboard" in Total Commander or collect "Location" + "File name" through the file properties. Somewhere the Russian x got in instead of the Latin x, and that's it, the path is wrong.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question