int main(int argc, char *argv[]) { //Error if there are not at least two commandline arguments if(argc < 2) output_usage_and_exit(argv[0]); //Open specified file, quit if cannot open std::ifstream in(argv[1]); if(!in){ std::cerr << "Couldn't open " << argv[1] << std::endl; exit (2); } //convert the infix expressions to postfix string infix; Stack<string> postfix; while(in>>infix){ //substrings out the infix expression minus the line return and //semi-colon. string temp = infix.substr(0,infix.length()-2); //splits the infix expression on spaces for easier processing. Stores in //it in vector. std::vector<string> vec = temp.split(' '); //function for converting infix expressions to postfix format. string result = infix2postfix(vec); //places the resulting string from the the conversion on the stack. postfix.push(result); } //done using the input file in.close(); //handles if an output file was specified on commandline if(argc==3){ std::ofstream out(argv[2]); if(!out){ std::cerr << "Couldn't open " << argv[2] <<std::endl; } while(!postfix.IsEmpty()){ out<< postfix.pop() << std::endl;} }else{ while(!postfix.IsEmpty()){ std::cout << postfix.pop() << std::endl;} } //successful return 0; }
int main(int argc, char *argv[]) { // Options std::vector<String> opt(3); opt[0] = "all"; opt[1] = "bytes"; opt[2] = "host"; // Error if there are not 3 things on the command line if (argc != 3) { output_usage_and_exit(argv[0], opt); } // Open file, quit if open fails std::ifstream in(argv[2]); if (!in) { std::cerr << "Couldn't open " << argv[2] << "\n"; exit(2); } // Process the log file std::vector<LogEntry> log_entries = parse(in); // Close the in file in.close(); // Handle the specified option String option(argv[1]); if (option == opt[0]) { // Output everything output_all(std::cout, log_entries); } else if (option == opt[1]) { // Output total number of bytes std::cout << "Total number of bytes sent: " << byte_count(log_entries) << std::endl; } else if (option == opt[2]) { // Host names will be out-putted here by_host(std::cout, log_entries); } else { std::cerr << "Unrecognized option: " << option << std::endl; std::cerr << "Recognized options: " << opt[0] << " " << opt[1] << " " << opt[2] << std::endl; } return 0; }
int main(int argc, char *argv[]) { //Error if less than 2 commandline arguments. Means user did not //specify input file. if(argc < 2) output_usage_and_exit(argv[0]); std::ifstream in(argv[1]); if(!in){ std::cerr << "Couldn't open: " << argv[1] << std::endl; exit(2); } string temp, infix; if(argc==3){ std::ofstream out(argv[2]); if(!out){ std::cerr << "Couldn't open: " << argv[2] << std::endl; exit(2); } while(in>>temp){ out << "Infix: " << temp << std::endl; infix = temp.substr(0, temp.length()-2); std::vector<string> vec = infix.split(' '); string postfix = infix2postfix(vec); out << "postfix: " << postfix << std::endl; std::vector<string> vec2 = postfix.split(' '); out << "Assembler:" << std::endl; Stack<string> assembler = postfix2assembler(vec2); outputassembler(out, assembler); } }else{