There are two solutions to this. You can either place the method above the method that calls it:
// basic file operations
#include <iostream>
#include <fstream>
using namespace std;
int writeFile ()
{
ofstream myfile;
myfile.open ("example.txt");
myfile << "Writing this to a file.\n";
myfile << "Writing this to a file.\n";
myfile << "Writing this to a file.\n";
myfile << "Writing this to a file.\n";
myfile.close();
return 0;
}
int main()
{
writeFile();
}
Or declare a prototype:
// basic file operations
#include <iostream>
#include <fstream>
using namespace std;
int writeFile();
int main()
{
writeFile();
}
int writeFile ()
{
ofstream myfile;
myfile.open ("example.txt");
myfile << "Writing this to a file.\n";
myfile << "Writing this to a file.\n";
myfile << "Writing this to a file.\n";
myfile << "Writing this to a file.\n";
myfile.close();
return 0;
}