Search code examples
c++xcodemacoscompiler-errorsfstream

ifstream' file not found on Mac


I'm using a Mac and I'm learning C++. I'm trying to open and read a file and I wrote a few lines code to do it. But when I compile it, either with gcc or g++ or clang, the compiler fails because it can't find the istream file. Is there a way to install or download the default library again. Thank you

Edit:

This is the code:

#include <ifstream>

using namespace std;

int main()
{
    ifstream ligand("ligand_dataset.txt");

    if( ligand.is_open())
    {
        cout << "File ok";
    }
    else cout << "Unable to open the file";

    return 0;
}

Solution

  • The ifstream header is replaced with fstream

    #include <fstream>
    
    int main()
    {
        std::ifstream f(....);
        return 0;
    }