I am done with my program and I am having trouble with the output text file. For my program, I already created an input file which my program will read into and I am also supposed to output the operations in my program to a text file. I made a text file on Notepad called "set_operations.txt". I implemented the ofstream commands in my program but it gives me a bunch of errors saying "outfile" is an undeclared identifier. Since I do not have a lot of experience with fstream, I was wondering where I should place my output text fie. Right now I have it opened and it is saved to my desktop. Is it supposed to be placed somewhere else. I put the input file in my program folder so should I do the same for the output text file. If so, where exactly in my program folder should I put it.
Here is my code. It is a long program but I just want you guys to check if I used my ifstream and ofstream correctly. Hopefully you guys could help. Thanks
code:
#include <iostream>
#include <fstream>
using namespace std;
void Union (int setA[10], int setB[10], int setU[20], int setNewU[20]);
void Intersection(int setA[10], int setB[10], int setX[10], int setNewX[10]);
void Differences(int setA[10], int setB[10], int setD[10], int setNewD[10], int setNewDtwo[10]);
int main()
{
ofstream outfile;
outfile.open("set_operations.txt");
ifstream infile;
int setA[10];
int setB[10];
int setU[20];
int setX[10];
int setD[10];
int setNewU[20];
int setNewX[10];
int setNewD[10];
int setNewDtwo[10];
int counter=0;
outfile<<"B - A : { ";
for(int i = 0; i < countItemsfour; i++)
{
outfile<<setNewDtwo[i]<<" ";
}//end for i
outfile<<"}"<<endl;
for(int i=0; i < sizeD; i++)
{
if(setNewDtwo[i]==setNewDtwo[i+1])
{
continue;
}
else
uniquefour++;
}
outfile<<"| B - A | : "<< uniquefour;
outfile<<endl<<endl;
}
OK guys I found out why the program was giving me a bunch of errors. I should declare the ofstream outfile before the main. But even when I do that and it is running, I still do not get an output. I know it has something to do with the output text file and where I should place. If you guys could help me out that would be great,
I'm new at this myself. I also notice that people out here seem to be reluctant to give much help with what might seem to be remedial prbs or studnts or hmwrk. But from what I understand, the compiler automatically produces the output file and creates it in the project file. You just have to make the input file(txt) and make sure you locate it in the project file. But the compiler creates the output file when you run the program. Assuming it runs successfully. Hope that's helpful.
It's not that people are reluctant to help at all.
People don't help out those who come here just asking for code to be written for them. And they may be a little reluctant to help if the problem can be found easily through search.
One thing that would help other people help you though would be to use the code tags and make your code a little more readable. When you make a new post if you look to the right hand side -------------------------------------> there is a "Format:" Section of buttons. The top-left button is for source code.