Trying to copy txt from one file to another

I am trying to copy text from one file while creating a new file and transferring the copied text over. Right now, I have created a new output file. However, nothing is getting copied. I don't know if my input file is never read in or my loop is not transferring the words. How do i check and fix this error in my program?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
int main()
{
	//input file
	const int maxLength = 10000;
	char filename[maxLength] = "D:/CS31/arrange.cpp/arrange.cpp/test.txt";
	ifstream infile(filename);

	//output file
	char outputFileName[maxLength] = "outfile.txt";
	ofstream outFile(outputFileName);

	getLine(infile, outFile);

	outFile.close();
	infile.close();
}

int getLine(istream &inf, ostream &outf)
{
	ifstream infile;
	ofstream outFile;

	char sentence[100000];
	
	while(!infile.eof())
	{
		infile.getline(sentence, 100000);
		outFile << sentence << endl;
	}

	return 0;
}
Last edited on
You declare new streams on line 20 & 21 instead of using the ones you are passing in.
oh i see.. how do really pass my files into my function? without declaring the ifstream and ofstream, my program said infile and outfile were undefined
Look at your function definition. >_>
wow. thank you LOL
Topic archived. No new replies allowed.