Home > Back-end >  Why can't open the test c. TXT file (source folder has a main function test. TXT file)
Why can't open the test c. TXT file (source folder has a main function test. TXT file)

Time:09-15

#include
#include

using namespace std;
Int main ()
{
Ifstream in;
In the open (" test. TXT ");
if(! In)
{
Cerr & lt; <"Failed to open the file" & lt; return 0;
}
Char x;
While (in & gt;> X)
{
Cout & lt; }
Cout & lt; in.close();
return 0;
}


C: \ Users \ \ Administrator \ 7 fileinout CLionProjects \ \ cmake - build - the debug \ 7 fileinout. Exe
Failed to open the file

Process is over, the exit code 0

CodePudding user response:

In the opening set a breakpoint there, and then input err in watch window, hr, check the error value

CodePudding user response:

In the absolute path
2. Put the file to the executable file directory at the same level

CodePudding user response:

You use the correct path, the test TXT to where natural machines don't know to open it

CodePudding user response:

Then do you like the char is also very strange, you try a string, it is better to STL vessel instead of C type
  • Related