fork download
  1. #include <iostream>
  2. #include <regex>
  3.  
  4. using namespace std;
  5.  
  6. const std::string CpuInfo =
  7. "Architecture: x86_64\n"
  8. "CPU op-mode(s): 32-bit, 64-bit\n"
  9. "Byte Order: Little Endian\n"
  10. "Address sizes: 43 bits physical, 48 bits virtual\n"
  11. "CPU(s): 12\n"
  12. "On-line CPU(s) list: 0-11\n"
  13. "Thread(s) per core: 2\n"
  14. "Core(s) per socket: 6\n"
  15. "Socket(s): 1\n"
  16. "NUMA node(s): 1\n"
  17. "Vendor ID: AuthenticAMD\n"
  18. "CPU family: 23\n"
  19. "Model: 1\n"
  20. "Model name: AMD Ryzen 5 1600 Six-Core Processor\n"
  21. "Stepping: 1\n"
  22. "CPU MHz: 2482.474\n"
  23. "CPU max MHz: 3200.0000\n"
  24. "CPU min MHz: 1550.0000\n"
  25. "BogoMIPS: 6387.25\n"
  26. "Virtualization: AMD-V\n"
  27. "L1d cache: 32K\n"
  28. "L1i cache: 64K\n"
  29. "L2 cache: 512K\n"
  30. "L3 cache: 8192K\n"
  31. "NUMA node0 CPU(s): 0-11";
  32.  
  33. int main() {
  34. std::regex reg_ex("CPU MHz:\\s+([^\\n]+)\\n?");
  35. std::smatch reg_match;
  36. std::string result = (std::regex_search(CpuInfo, reg_match, reg_ex)) ?
  37. reg_match[1] : std::string("Not found!");
  38. std::cout << "CPU MHz: " << result << std::endl;
  39. return 0;
  40. }
Success #stdin #stdout 0s 4352KB
stdin
Standard input is empty
stdout
CPU MHz: 2482.474