Hi, I began file I/O and I did exactly what it said in the book I was using and it doesn't seem to work for some reason. Am I doing something wrong?

#include <iostream>
#include <fstream>

using namespace std;

int main()
{
    ifstream fin("hello.txt");
    if (fin.is_open())
        cout << "It's good";
    else
        cout << "Not good";

    return 0;
}

ran the code it compiled fine ran and did what it was supposed todo

what seems to be the problem?

Does "It's good" ever come up on the screen? It never comes up for me even though I have a hello.txt file.

oh wow no it doesn't i caught it now you never open the file after you declare it

heres some code from one of my projects for and example

//opens and test for exsistence of data files
	inFile.open(inputFile);
	outFile.open(outputFile, ios::app);
	if(! inFile || ! outFile)
	{
		cout << "No such input/output file exsists";
	}

Edited 5 Years Ago by alex55: code

I got the answer! I'm a noob, haha. Still really a beginner. The file was in the desktop, so I looked around the Internet and I found that I had to put it in the project folder. Thanks so much for your answers!

This question has already been answered. Start a new discussion instead.