fork download
  1. #include <iostream>
  2. #include <fstream>
  3. #include <string>
  4. #include <vector>
  5. #include <algorithm>
  6.  
  7. void processGCodeFile(const std::string& inputFilePath, const std::string& outputFilePath) {
  8. std::ifstream inputFile(inputFilePath);
  9. std::ofstream outputFile(outputFilePath);
  10. std::string line;
  11.  
  12. if (!inputFile.is_open() || !outputFile.is_open()) {
  13. std::cerr << "Error opening file." << std::endl;
  14. return;
  15. }
  16.  
  17. while (std::getline(inputFile, line)) {
  18. std::replace(line.begin(), line.end(), ';', '%');
  19.  
  20. if (line.find("G00") != std::string::npos) {
  21. outputFile << "M05" << std::endl;
  22. }
  23. outputFile << line << std::endl;
  24. if (line.find("G00") != std::string::npos) {
  25. outputFile << "M03" << std::endl;
  26. }
  27. }
  28.  
  29. inputFile.close();
  30. outputFile.close();
  31. }
  32.  
  33. int main() {
  34. std::string inputFilePath = "input.gcode"; // Replace with actual input file path
  35. std::string outputFilePath = "output.gcode"; // Replace with actual output file path
  36.  
  37. processGCodeFile(inputFilePath, outputFilePath);
  38. std::cout << "Processing completed." << std::endl;
  39.  
  40. return 0;
  41. }
  42.  
Success #stdin #stdout #stderr 0.01s 5316KB
stdin
Standard input is empty
stdout
Processing completed.
stderr
Error opening file.