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";
        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
	outFile.open(outputFile, ios::app);
	if(! inFile || ! outFile)
		cout << "No such input/output file exsists";

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!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.19 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.