fork download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. int main()
  5. {
  6. char ch, next;
  7.  
  8. cout << "Enter C program (Ctrl+D to finish):\n";
  9.  
  10. while (cin.get(ch))
  11. {
  12. if (ch == '/')
  13. {
  14. if (cin.get(next))
  15. {
  16. // Single-line comment
  17. if (next == '/')
  18. {
  19. while (cin.get(ch) && ch != '\n')
  20. ;
  21.  
  22. if (ch == '\n')
  23. cout << '\n';
  24. }
  25.  
  26. // Multi-line comment
  27. else if (next == '*')
  28. {
  29. while (cin.get(ch))
  30. {
  31. if (ch == '*')
  32. {
  33. if (cin.get(next) && next == '/')
  34. break;
  35. }
  36. }
  37. }
  38.  
  39. // Normal division operator
  40. else
  41. {
  42. cout << '/';
  43. cout << next;
  44. }
  45. }
  46. }
  47. else
  48. {
  49. cout << ch;
  50. }
  51. }
  52.  
  53. return 0;
  54. }
Success #stdin #stdout 0s 5308KB
stdin
Standard input is empty
stdout
Enter C program (Ctrl+D to finish):