c++ - I have errors with the following code -


i have errors following code , not sure doing wrong. compiler microsoft visual c++ 2010. code compiles c++ source file through system() function , runs resulting program given input file. program compares output file generated program expected result file determine whether or not program correct. following code is:

#include <iostream> #include <fstream> using namespace std;  string getfile(string); int execute(string,string); void checkit(ifstream&,ifstream&);  int main() {     string command;     string input,output,source,expected;     ifstream in,exp;     int code;     source=getfile("source");     input=getfile("input");     expected=getfile("expected result");      code=execute(source,input);     if(code!=0) {         cout<<"execution error,program aborted!\n";         system("pause");         return 0;     }      in.open("output.txt");          //open file     if(in.fail()) {           //is ok?         cout<<"created output file did not openplease check it\n";         system("pause");         return 1;     }      exp.open(expected.c_str());          //open file     if(exp.fail()) {            //is ok?         cout<<"expected output file did not openplease check it\n";         system("pause");         return 1;     }            checkit(in,exp);     in.close();     exp.close();     system("pause");     return 0; }  void checkit(ifstream& act,ifstream& exp) {     int i,error=0,j;     int n,m,total=0;     act>>n;     exp>>m;     while(act&&exp) {         total++;         if(n!=m)             error++;         act>>n;         exp>>m;         }     if(act || exp)         error++;      if(error==0)         cout<<"the output of program iscorrect.\n";     else         cout<<"the output of theprogram not correct.\n";      cout<<"your grade is"<<(total-error)/(double)total*100.<<"%\n";      }      int execute(string source,string input) {     string command,minusc;     int c,pos;     pos=source.find('.',0);     minusc=source.substr(0,pos);     command="gcc -o "+minusc+" "+source;     c=system(command.c_str());     if(c!=0) {         cout<<"compilation error\n";         return c;     }     command=minusc+" "+input+" > output.txt";     c=system(command.c_str());     if(c!=0)         cout<<"execution error\n";     return c; }  string getfile(string mess) {     string file;     cout<<"please enter name of "<<mess<<"file: ";     cin>>file;     return file; } 

you should compiler errors were. tried in visual studio , turns out need

#include <string> 

at top of file.


Comments

Popular posts from this blog

user interface - How to replace the Python logo in a Tkinter-based Python GUI app? -

objective c - Greedy NSProgressIndicator Allocation -

how to set an OCR language in Google Drive -