fork download
  1. //Функция
  2. ifstream file(filename);
  3.  
  4. string str;
  5. smatch result;
  6. regex rx ("class\s+([^\s:]*)\s*:\s*(?:virtual)?\s+(?:public\s+|private\s+|protected\s+)?([^\s,]*)(?:\s*,\s*(?:virtual)?\s+(?:public\s+|private\s+|protected\s+)?([^\s,]*))*");
  7.  
  8. while (!file.eof()) {
  9. getline(file, str);
  10. cout << str << endl << endl;
  11. while (regex_search(str, result, rx)) {
  12. for (auto x : result) std::cout << x << " ";
  13. std::cout << std::endl;
  14. str = result.suffix().str();
  15. }
  16. }
  17.  
  18.  
  19.  
  20. //.txt
  21. class Parent: {};
  22. class Child: virtual public Parent {};
  23. class Child2: virtual public Parent {};
  24. class Child3: virtual public Child, virtual public Child2 {};
  25. class Child4: virtual public Child, virtual public Child6 {};
  26. class Child5: virtual public Child {};
  27. class Child6: virtual public Parent, virtual public Child3 {};
  28. class Child7: virtual public Child3, virtual public Child {};
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp:2:2: error: 'ifstream' does not name a type
  ifstream file(filename);
  ^
prog.cpp:4:2: error: 'string' does not name a type
  string str;
  ^
prog.cpp:5:2: error: 'smatch' does not name a type
  smatch result;
  ^
prog.cpp:6:2: error: 'regex' does not name a type
  regex rx ("class\s+([^\s:]*)\s*:\s*(?:virtual)?\s+(?:public\s+|private\s+|protected\s+)?([^\s,]*)(?:\s*,\s*(?:virtual)?\s+(?:public\s+|private\s+|protected\s+)?([^\s,]*))*");
  ^
prog.cpp:8:2: error: expected unqualified-id before 'while'
  while (!file.eof()) {
  ^
stdout
Standard output is empty