Is there any reason why the code below won't work (I mean as far as writing output to file, not as far as writing the correct output to the file):
#include <cstdio>
#include <iostream>
#include <fstream>
using namespace std;
int main()
{
ofstream fout ("ride.out");
ifstream fin ("ride.in");
char comet[6] = {0,0,0,0,0,0};
char group[6] = {0,0,0,0,0,0};
int comet_buffer = 1;
int group_buffer = 1;
fin >> comet;
fin >> group;
cout << comet << endl << group;
for(int i = 0;i < 6;i++)
{
if(comet[i] != 0)
{
comet_buffer *= (int)(comet[i]-64);
}
}
for(int n = 0;n < 6;n++)
{
if(group[n] != 0)
{
group_buffer *= (int)(group[n]-64);
}
}
if(comet_buffer%47 == group_buffer%47)
{
fout << "GO\n";
}
else
{
fout << "STAY\n";
}
return 0;
}
I have a file called ride.in, and it contains the word COMETQ on one line, and HVNGAT on the second line. The program did not create a file called ride.out. I tried manually creating one and running it again, and the file was still empty after the program ran.
Also, this is for an online programming competition thing (this is practice, not the actual thing). They give an example of code on how to use fstream. I copied the code exactly into my compiler (they encourage you to for testing purposes, so I know the code is a complete program), I run it, and no file is created for output. i.e the program doesn't work. is there anything that might be causing this?
Also worth noting that you submit ur .cpp file to their site, and they compile for you. the test code works when you upload it to their site, just not on my machine. im asking this because the code at the very top works for neither my machine or theirs (though, on mine, it just doesn't write output, on theirs, I get a run time error).
Thanks