Error opening file when debugging

后端 未结 1 1650
情歌与酒
情歌与酒 2021-01-28 18:04

When i try to run the following program:

// ConsoleApplication1.cpp : Defines the entry point for the console application.
//

#include \"stdafx.h\"
#include <         


        
相关标签:
1条回答
  • 2021-01-28 18:39

    Try this:

    // ConsoleApplication1.cpp : Defines the entry point for the console application.
    //
    
    #include "stdafx.h"
    #include <fstream>
    #include <iostream>
    
    
    int _tmain(int argc, _TCHAR* argv[])
    {
        std::ifstream inFile("c:\\test.txt");
    
        if(!inFile.is_open())
        {
            std::cout << "Doesn't work" << std::endl;
        }
    
        inFile.close();
        return 0;
    }
    

    This should work if you put your file to C:\test.txt. The rest is up to you to figure out. Relative paths work, you need to make sure the file is where your program looks for it (or the other way 'round). Try to print out the current path if you are unsure what's wrong.

    0 讨论(0)
提交回复
热议问题