So I'm trying to write a program that gets a whole bunch of numbers from a file called 'mean.txt', and find the average. I've tried sending the stream called 'ios' to a function, but it keeps telling me that "Identifier 'istream&' is unidentified" and that "Identifier 'ios' is unidentified"
#include <iostream>
#include <fstream>
double find_average(istream& ios); //I get 2 errors here telling me that 'istream' and 'ios' are unidentified
int main()
{
usingnamespace std;
ifstream ios;
double average;
ios.open("mean.txt");
if (ios.fail())
{
cout << "Failed to open 'mean.txt'";
system("pause");
exit(1);
}
average = find_average(ios); //There's an error here that says I need a (pointer-to-) function
}
double find_average(istream& ios) //I get the same identifier problems here
{ //This line tells me that it expected a ';' What's that all about????
usingnamespace std;
double next, sum, count, average;
while (ios >> next)
{
sum = sum + next;
count++;
}
average = sum / count;
return average;
}
Thanks Moschops. I'd actually figured out the problem on my own.
But what if I wanted to use multiple namespaces in a single program? That's why I origianally had them in individual blocks. I know this program wouldn't need multiple namespaces, but I guess its just habit...