fork download
  1. enum difficult{EASY, MEDIUM, HARD};
  2. using tab = QPair<difficult, QPair<QString,int>>;
  3. std::multiset<tab, std::function<bool(tab,tab)>>* table;
  4. HighScores::HighScores(QWidget *parent) :
  5. QDialog(parent),
  6. ui(new Ui::HighScores)
  7. {
  8. ui->setupUi(this);
  9. auto comp = [](tab a, tab b){ return a.first < b.first ? true : a.first == b.first ? a.second.second < b. second.second : false;};
  10. table = new std::multiset<tab, std::function<bool(tab,tab)>>(comp);
  11. std::string str, name;
  12. int time,di;
  13. file = new QFile("records.txt");
  14. if (file->exists()){
  15. file->open(QIODevice::ReadOnly);
  16. while(!file->atEnd()){
  17. str = file->readLine().toStdString();
  18. std::istringstream a(str);
  19. a >> name;
  20. a >> time;
  21. a >> di;
  22. table->insert(tab(static_cast<difficult>(di), QPair<QString,int>(QString(name.c_str()), time) ));
  23. }
  24. file->resize(0);
  25. file->close();
  26. }
  27. }
  28.  
  29. HighScores::~HighScores()
  30. {
  31. delete ui;
  32. }
  33.  
  34. void HighScores::callAddIf(difficult diff){
  35. emit gettime();
  36. int h = 0;
  37.  
  38. for(auto& i : *table)
  39. if(i.first==diff)
  40. h++;
  41. auto temp = *table->lower_bound(tab(diff,QPair<QString,int>("",0)));
  42. for(auto& i : *table)
  43. if(i.first == diff)
  44. temp = i;
  45. if(h < 10 || temp.second.second > time){
  46. QString name = QInputDialog::getText(this,"New Record", "Your name");
  47. if(name.size()>0)
  48. table->insert(tab(diff,QPair<QString,int>(name, time)));
  49. if(h == 10){
  50.  
  51. table->erase(table->find(temp));
  52. }
  53. }
  54. file->open(QIODevice::WriteOnly);
  55. for(auto& i : *table)
  56. file->write(i.second.first.toUtf8()+ " " + QString::number(i.second.second).toUtf8() + " " + QString::number(i.first).toUtf8() + "\n");
  57. file->close();
  58.  
  59. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp:2:14: error: ‘QPair’ does not name a type
 using  tab = QPair<difficult, QPair<QString,int>>;
              ^~~~~
prog.cpp:3:6: error: ‘multiset’ in namespace ‘std’ does not name a template type
 std::multiset<tab, std::function<bool(tab,tab)>>* table;
      ^~~~~~~~
prog.cpp:3:1: note: ‘std::multiset’ is defined in header ‘<set>’; did you forget to ‘#include <set>’?
prog.cpp:1:1:
+#include <set>
 enum difficult{EASY, MEDIUM, HARD};
prog.cpp:3:1:
 std::multiset<tab, std::function<bool(tab,tab)>>* table;
 ^~~
prog.cpp:4:1: error: ‘HighScores’ does not name a type
 HighScores::HighScores(QWidget *parent) :
 ^~~~~~~~~~
prog.cpp:29:1: error: ‘HighScores’ does not name a type
 HighScores::~HighScores()
 ^~~~~~~~~~
prog.cpp:34:6: error: ‘HighScores’ has not been declared
 void HighScores::callAddIf(difficult diff){
      ^~~~~~~~~~
prog.cpp: In function ‘void callAddIf(difficult)’:
prog.cpp:35:5: error: ‘emit’ was not declared in this scope
     emit gettime();
     ^~~~
prog.cpp:38:20: error: ‘table’ was not declared in this scope
     for(auto& i : *table)
                    ^~~~~
prog.cpp:38:20: note: suggested alternative: ‘mutable’
     for(auto& i : *table)
                    ^~~~~
                    mutable
prog.cpp:41:18: error: ‘table’ was not declared in this scope
     auto temp = *table->lower_bound(tab(diff,QPair<QString,int>("",0)));
                  ^~~~~
prog.cpp:41:18: note: suggested alternative: ‘mutable’
     auto temp = *table->lower_bound(tab(diff,QPair<QString,int>("",0)));
                  ^~~~~
                  mutable
prog.cpp:41:46: error: ‘QPair’ was not declared in this scope
     auto temp = *table->lower_bound(tab(diff,QPair<QString,int>("",0)));
                                              ^~~~~
prog.cpp:41:52: error: ‘QString’ was not declared in this scope
     auto temp = *table->lower_bound(tab(diff,QPair<QString,int>("",0)));
                                                    ^~~~~~~
prog.cpp:41:60: error: expected primary-expression before ‘int’
     auto temp = *table->lower_bound(tab(diff,QPair<QString,int>("",0)));
                                                            ^~~
prog.cpp:41:37: error: ‘tab’ was not declared in this scope
     auto temp = *table->lower_bound(tab(diff,QPair<QString,int>("",0)));
                                     ^~~
prog.cpp:45:39: error: ‘time’ was not declared in this scope
     if(h < 10 || temp.second.second > time){
                                       ^~~~
prog.cpp:46:16: error: expected ‘;’ before ‘name’
         QString name = QInputDialog::getText(this,"New Record", "Your name");
                ^~~~~
                ;
prog.cpp:47:12: error: ‘name’ was not declared in this scope
         if(name.size()>0)
            ^~~~
prog.cpp:48:50: error: expected primary-expression before ‘int’
             table->insert(tab(diff,QPair<QString,int>(name, time)));
                                                  ^~~
prog.cpp:54:5: error: ‘file’ was not declared in this scope
     file->open(QIODevice::WriteOnly);
     ^~~~
prog.cpp:54:16: error: ‘QIODevice’ has not been declared
     file->open(QIODevice::WriteOnly);
                ^~~~~~~~~
prog.cpp:56:52: error: ‘QString’ is not a class, namespace, or enumeration
         file->write(i.second.first.toUtf8()+ " " + QString::number(i.second.second).toUtf8() + " " + QString::number(i.first).toUtf8() + "\n");
                                                    ^~~~~~~
prog.cpp:56:102: error: ‘QString’ is not a class, namespace, or enumeration
         file->write(i.second.first.toUtf8()+ " " + QString::number(i.second.second).toUtf8() + " " + QString::number(i.first).toUtf8() + "\n");
                                                                                                      ^~~~~~~
stdout
Standard output is empty