How to...Please???!!

how to open a .txt file?????

Am i doing anything wrong on this function?????

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
int openFiles(ifstream& inFile, ofstream& outFile) 
{
	inFile.open("example.txt");

                if (!inFile) 
               { 
                   cout << "Unable to open the file." <<endl; 
                   system("PAUSE"); 
    
                   return 1; 
                } 

	outFile.open("exampleOut.txt");
	outFile << fixed << showpoint << setprecision(2);

}


the way it is it's not opening the file. I do not know what i did wrong???
Anyone with some advice or hints please....

Thanks in advance everyone
Last edited on
Well I don't know why you would pass in references to fstreams... and have your file names hard coded... is there an "example.txt" where you think there is? What happens, does the compiler yell at you?
yes there is a file with that name and is inside my procject that i created.

Also im not sure if this helps but i do get "exampleOut.txt" file but it is blank.
Last edited on
I would expect the output.txt to come out, is the other file in the same place?
yes the input file is in the same place (folder)
Haha alright =)
when you say it doesn't open it, is your message popping up, or what?
outFile << fixed << showpoint << setprecision(2);

What do you expect that line to write to outFile? Those are just manipulators, there's no data.
yes my message is showing.
Last edited on
filipe, thanks for the reply but that is just some part of the code.

Sory about that
Well, obviously we won't be able to tell what's going on if the part you posted works as desired.

You're not reusing those streams, are you? You really should instantiate them inside the function instead of passing them.
sorry
Last edited on
//initialize(inFile, outFile);
thats a type error....not supposed to be there
Then you need to call initialize() from main() after you open the files. As it is, the program should work just as you described.
it still does the same...
i got it
Last edited on
Topic archived. No new replies allowed.