I have figured out how to do this using stdio.h, but I am not sure how to do this with iostream/fstream. Here is the example code that is working:
[cpp]
#include <stdio.h>
#ifndef ONLINE_JUDGE
FILE *fin = fopen("myprog.in", "r");
FILE *fout = fopen("myprog.out", "w");
#else
FILE *fin = stdin;
FILE *fout = stdout;
#endif
int main(){
unsigned int n,i,j,max=0;
long temp;
while (fscanf(fin,"%d",&i)==1){
...
if (ch==0)fprintf(fout,"%d %d %d\n",i,j,max);
else fprintf(fout,"%d %d %d\n",j,i,max);
}
return 0;
}
[/cpp]
I need to have the users to be able to do this with the C++ style of coding rather than C. I want them to have the option to do both. There was a posting up here before, but I can't find it.
Thanks
ONLINE_JUDGE with C++
Moderator: Board moderators
ONLINE_JUDGE with C++
Cheers,
Ron
Ron
Believe it or not, there is actually a reason why there is a C++ forum.
http://online-judge.uva.es/board/viewforum.php?f=14
You can do like this, and use cin/cout as usual:
[cpp]#include<fstream>
#include<iostream>
void init() {
#ifndef ONLINE_JUDGE
cin.rdbuf((new ifstream("T.in"))->rdbuf());
cout.rdbuf((new ofstream("T.out"))->rdbuf());
#endif
}[/cpp]
Or, you could have two global i/ofstream variables which are just the same as cin/cout if ONLINE_JUDGE is defined, similarly to what you did in the C case.
http://online-judge.uva.es/board/viewforum.php?f=14
You can do like this, and use cin/cout as usual:
[cpp]#include<fstream>
#include<iostream>
void init() {
#ifndef ONLINE_JUDGE
cin.rdbuf((new ifstream("T.in"))->rdbuf());
cout.rdbuf((new ofstream("T.out"))->rdbuf());
#endif
}[/cpp]
Or, you could have two global i/ofstream variables which are just the same as cin/cout if ONLINE_JUDGE is defined, similarly to what you did in the C case.