main .cpp not including a func-proto header file

My function definition .cpp file includes my header file fine, but my main() .cpp file doesn't. First definition (for opening my input and output files) isn't assimilating from the first .cpp file.
1) Is this causing my header to fail in the main() file.
2) And what am I missing in my declaration or definition that is failing my file opening function?

Relevant code:

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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#ifndef MFP1_H
#define MFP1_H

// Include files
#include <iostream>
#include <fstream>
#include <string>
#include <iomanip>

//Function prototypes

int fnOpenFiles(ifstream&, ofstream&);
	//	a. Open input file, open output file
void fnInitialize(char&);
	//	a. Initialize variables.
void fnInitialize(double&);
	//	a. Initialize variables.
void fnInitialize(int&);
	//	a. Initialize variables.
void fnInitialize(string&);
	//	a. Initialize variables.
void fnSumGrades(char&, double, double&, double&, int&, int&);
	//	a. Sum the GPAs and accumulate count for each gender
double fnAverageGrade(int, double);
	//	a. Average male GPAs, average female GPAs.
void fnPrintResults(string, double, ofstream&);
	//	a. Output results to OutFile--floating point number
void fnPrintResults(string, int, ofstream&);
	//	a. Output results to OutFile--integer number

#endif


// MFP1.cpp

#include "MFP1.h"

int fnOpenFiles(ifstream& inFile, ofstream& outFile)		// Open input file: Ch7_Ex6Data.txt, open output file: Ch7_Ex6out.txt
{
	// Open input file

	inFile.open("Ch7_Ex6Data.txt");

	// Input file success check
	if(!inFile)
	{
		cout << "Cannot open file--program terminated!";

		system("pause");
		return 1;											// Return that error code
	}

	// Open output file
	outFile.open("Ch7_Ex6out.txt");
	// Set ouput format
	outFile << fixed << showpoint << setprecision(2);
	return 0;
}



Last edited on
What do you mean by this? Any errors? What IDE do you use?
My problem is that when I add existing files to my solution (VS2010), I can't get them into the same directory from within VS. The original problem was that my main() file was an altered file from another project/solution and didn't 'copy' to the current project's directory. I went outside the IDE and moved the file the long way using WinExp.

Original symptom solved, underlying problem still there.
My function definition .cpp file includes my header file fine, but my main() .cpp file doesn't. First definition (for opening my input and output files) isn't assimilating from the first .cpp file.


If you try to use a function in main.cpp, then main.cpp must have the function definition or declaration in it (whether written into main.cpp or put there by the preprocessor thanks to a #include ) at some point before you try to use the function.

Having that function definition or declaration in some other cpp file (for example, by #include ing a relevant header file in that other cpp file) has no bearing whatsoever on this. Every cpp file is compiled independently as a completely separate unit.
Again, the original problem was main() .cpp file not going outside the home directory for the header file. I presume I need to set some environment parameters on VS2010 when I have a home for my boilerplate function headers/files. Until then I still need to figure out how to copy or move a file to my solution directory while I'm in the IDE itself. That one has me stumped at the moment.
Topic archived. No new replies allowed.