online compiler and debugger for c/c++

code. compile. run. debug. share.
Source Code   
Language
#include <iostream> #include<string> #include<algorithm> #include<cstring> using namespace std; string extracttoken(string temp,int key) { char *s=strtok((char *)temp.c_str()," "); while(key>1) { s=strtok(NULL," "); key--; } return (string)s; } int convert_to_int(string number) { int ans=0,power=1; for(int i=number.length()-1;i>=0;i--) { ans +=((number[i]-'0')*power); power=power*10; } return ans; } bool compare_numeric(pair<string,string> s1,pair<string,string>s2) { string key1,key2; key1=s1.second; key2=s2.second; return convert_to_int(key1)<convert_to_int(key2); } bool comparelexico(pair<string,string> s1,pair<string,string>s2) { string key1,key2; key1=s1.second; key2=s2.second; return key1<key2; } int main() { int total_string; cin>>total_string; cin.get(); string s[100]; for(int i=0;i<total_string;i++) { getline(cin,s[i]); } int key; string reversal,ordering; cin>>key; cin>>reversal>>ordering; pair <string,string> s1[100]; for(int i=0;i<total_string;i++) { s1[i].first=s[i]; s1[i].second=extracttoken(s[i],key); } if(ordering=="numeric") { sort(s1,s1+total_string,compare_numeric); } else { sort(s1,s1+total_string,comparelexico); } if(reversal=="true") { int i=0; while(i<total_string/2) { swap(s1[i],s1[total_string-i-1]); } } for(int i=0;i<total_string;i++) { cout<<s1[i].first<<endl; } }

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