MPGHCC: How to File Input
Ok since many people cant file input ;D im going to make a thread on inputting data through a file, specifically for the MPGHCC. There are two ways to do it it but i prefer the first one:
Method One:
Method two:
Method One:
Code:
#include <iostream>
using namespace std;
int main(void){
freopen("input1.txt","r",stdin);
int i;
for(i=0;i<5;i++) //for all 5 test cases
{
int n;
cin>> n; //input n from file
cout<<n*3<<endl; //output to screen
}
}
Code:
#include <iostream>
#include <fstream>
using namespace std;
int main(void){
ifstream fin("input1.txt");
int i;
for(i=0;i<5;i++){
int n;
fin>>n; //read from file
cout<<n*3<<endl; //output to screen
}
}