online compiler and debugger for c/c++

code. compile. run. debug. share.
Source Code   
Language
#include <iostream> #include <string> #include <sstream> #include <fstream> #include <vector> #include <queue> #include "ArgumentManager.h" using namespace std; queue<string> splitStringUsingComma(string text) { queue<string> sol; stringstream ss(text); while(ss.good()) { string x; getline(ss,x,','); sol.push(x); } return sol; } int main(int argc, char* argv[]) { ArgumentManager am(argc, argv); ifstream input; string infileName = am.get("input"); string outfileName = am.get("output"); input.open("input.txt"); string text; queue<string> queue1,queue2; getline(input,text); queue1 = splitStringUsingComma(text); text.clear(); getline(input,text); queue2 = splitStringUsingComma(text); queue<string> queue3; int cost{0}; vector<string> sol; while(!queue1.empty()) { if(queue1.front().find("compsci")!=string::npos) { sol.push_back(queue1.front()); cost+=20; } else { queue3.push(queue1.front()); cost+=10; } queue1.pop(); } while(!queue2.empty()) { if(queue2.front().find("compsci")!=string::npos) { sol.push_back(queue2.front()); cost+=20; } else { queue3.push(queue2.front()); cost+=10; } queue2.pop(); } while(!queue3.empty()) { sol.push_back(queue3.front()); queue3.pop(); cost+=20; } ofstream output; output.open("output.txt"); output<<cost<<'\n'; // for(string x:sol) // { // output<<x<<","; // } for(int i = 0; i < sol.size() -1 ; ++i) { output << sol.at(i)<<","; } output << sol.back(); output<<endl; input.close(); output.close(); return 0; }
#include <map> #include <string> #include <iostream> #include <sstream> using namespace std; class ArgumentManager { private: map<string, string> m_argumentMap; public: ArgumentManager() { } ArgumentManager(int argc, char *argv[], char delimiter=';'); ArgumentManager(string rawArguments, char delimiter=';'); void parse(int argc, char *argv[], char delimiter=';'); void parse(string rawArguments, char delimiter=';'); string get(string argumentName); string toString(); friend ostream& operator << (ostream &out, ArgumentManager &am); }; void ArgumentManager::parse(string rawArguments, char delimiter) { stringstream currentArgumentName; stringstream currentArgumentValue; bool argumentNameFinished = false; for (unsigned int i=0; i<=rawArguments.length(); i++) { if (i == rawArguments.length() || rawArguments[i] == delimiter) { if (currentArgumentName.str() != "") { m_argumentMap[currentArgumentName.str()] = currentArgumentValue.str(); } // reset currentArgumentName.str(""); currentArgumentValue.str(""); argumentNameFinished = false; } else if (rawArguments[i] == '=') { argumentNameFinished = true; } else { if (argumentNameFinished) { currentArgumentValue << rawArguments[i]; } else { // ignore any spaces in argument names. if (rawArguments[i] == ' ') continue; currentArgumentName << rawArguments[i]; } } } } void ArgumentManager::parse(int argc, char *argv[], char delimiter) { if (argc > 1) { for (int i=1; i<argc; i++) { parse(argv[i], delimiter); } } } ArgumentManager::ArgumentManager(int argc, char *argv[], char delimiter) { parse(argc, argv, delimiter); } ArgumentManager::ArgumentManager(string rawArguments, char delimiter) { parse(rawArguments, delimiter); } string ArgumentManager::get(string argumentName) { map<string, string>::iterator iter = m_argumentMap.find(argumentName); //If the argument is not found, return a blank string. if (iter == m_argumentMap.end()) { return ""; } else { return iter->second; } } string ArgumentManager::toString() { stringstream ss; for (map<string, string>::iterator iter = m_argumentMap.begin(); iter != m_argumentMap.end(); iter++) { ss << "Argument name: " << iter->first << endl; ss << "Argument value: " << iter->second << endl; } return ss.str(); } ostream& operator << (ostream &out, ArgumentManager &am) { out << am.toString(); return out; }
chemistry,compsci A,bio A,english B compsci B,compsci D,compsci C
170 compsci A,compsci B,compsci D,compsci C,chemistry,bio A,english B

Compiling Program...

Command line arguments:
Standard Input: Interactive Console Text

                

                

Program is not being debugged. Click "Debug" button to start program in debug mode.

#FunctionFile:Line
VariableValue
RegisterValue
ExpressionValue