0

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;
}
2
Contributors
4
Replies
5
Views
6 Years
Discussion Span
Last Post by blee93
0

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

what seems to be the problem?

0

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

0

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 by alex55: code

0

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.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.