fork download
  1. #include <iostream>
  2. #include <fstream>
  3. #include <string>
  4. using namespace std;
  5.  
  6. enum mod {decrease, increase};
  7. mod status;
  8. string ntime;
  9. string str_input;
  10. void choice_mod();
  11. void choice_newtime();
  12. void set_newtime();
  13. int main()
  14. {
  15. setlocale(LC_CTYPE, "Russian");
  16.  
  17. choice_mod();
  18. choice_newtime();
  19. set_newtime();
  20. system("pause");
  21. }
  22.  
  23. void choice_mod ()
  24. {
  25. char c;
  26. cout << "Какой режим вы хотите использовать?\n"
  27. << "Если нужно использовать режим увелечения времени, то напишите +\n"
  28. << "А если нужен режим уменьшения времени, то напишите -\n";
  29. do
  30. {
  31. cin >> c;
  32. if((c != '+') && (c != '-'))
  33. cout << "Неправильный символ! Повторите ввод.\n";
  34. }
  35. while((c != '+') && (c != '-'));
  36. if(c == '+')
  37. status = increase;
  38. else
  39. status = decrease;
  40. }
  41.  
  42. void choice_newtime()
  43. {
  44.  
  45. size_t t_size = 12;
  46. size_t count_symb = 0;
  47. size_t count_num = 0;
  48. size_t count_sum;
  49. cout << "Введите начальное время в формтае - 00:00:00,000 час/минута/секунда/миллисекунда\n";
  50. do
  51. {
  52. getline(cin, ntime);
  53. if(ntime.length() > 0){
  54. for(size_t i = 0; i < ntime.length() && !(i > t_size); i++)
  55. {
  56. if((i == 2 && ntime[i] == ':') || (i == 5 && ntime[i] == ':') || (i == 8 && ntime[i] == ',') && (count_symb <= 3))
  57. {
  58. ++count_symb;
  59. }
  60. if((i != 2 || i != 5 || i != 8) && (ntime[i] >= '0' && ntime[i] <= '9') && (count_num <= 9))
  61. {
  62. ++count_num;
  63. }
  64. }
  65. cout << "\n" << count_symb;
  66. cout << "\n" << count_num;
  67. cout << "\n";
  68. count_sum = count_symb + count_num;
  69. if(count_sum < t_size || count_sum > t_size)
  70. {
  71. count_symb = 0;
  72. count_num = 0;
  73. ntime = "";
  74. cout << "Неправльные данные! Повторите ввод.\n";
  75. }
  76. }
  77.  
  78. }
  79. while(count_sum != t_size);
  80. }
  81.  
  82. void set_newtime()
  83. {
  84.  
  85. string input_filename = "1.srt";
  86. string output_filename = "2.srt";
  87. ifstream input;
  88. ofstream output;
  89. input.open("D:\\subtitles\\Release\\" + input_filename);
  90. output.open("D:\\subtitles\\Release\\" + output_filename);
  91. while(input)
  92. {
  93. getline(input, str_input);
  94. if(str_input[2] == ':' && str_input[5] == ':')
  95. {
  96. for(int i = 0; i < str_input.length(); i+=17)
  97. {
  98. for(int j = 0; j < ntime.length(); j++)
  99. {
  100. if((str_input[j+i] != ':') && (str_input[j+i] != ','))
  101. {
  102. if(status == increase)
  103. {
  104. if((char((str_input[j+i] + ntime[j]) - 48)) > '9')
  105. {
  106. if((j == 0) || (j == 17))
  107. {
  108. cout << "достигнуто максимальное время";
  109. }
  110. else
  111. {
  112. str_input[j+i-1]++;
  113. str_input[j+i] = ntime[j] - 1;
  114. }
  115. }
  116. else
  117. {
  118. str_input[j+i] = char((str_input[j+i] + ntime[j]) - 48);
  119. }
  120. }
  121. if(status == decrease)
  122. {
  123.  
  124. if(char((str_input[j+i] - ntime[j]) + 48) < '0')
  125. {
  126. if((j == 0) || (j == 17))
  127. {
  128. str_input[j+i] = '0';
  129. cout << "Достигнуто минимальное время";
  130. }
  131. else
  132. {
  133.  
  134.  
  135. if((str_input[j+i-1] > '0') && (str_input[j+i-1] <= '9'))
  136. {
  137. str_input[j+i-1]--;
  138. str_input[j+i] = char(((str_input[j+i] - 38) - (ntime[j] - 48)) + 48);
  139. str_input[j+i] = '0';
  140.  
  141. }
  142. else
  143. if(((str_input[j+i-1] == ':') || (str_input[j+i-1] == ',')) && (str_input[j+i-2] > '0'))
  144. {
  145. str_input[j+i-2]--;
  146.  
  147. str_input[j+i] = char(((str_input[j+i] - 38) - (ntime[j] - 48)) + 48);
  148. str_input[j+i] = '0';
  149. }
  150.  
  151. }
  152. }
  153. else
  154. {
  155. str_input[j+i] = char((str_input[j+i] - ntime[j]) + 48);
  156. }
  157. }
  158. }
  159. }
  160. }
  161. }
  162. str_input.push_back('\n');
  163. output.write(str_input.c_str(), str_input.size());
  164. }
  165. }
  166.  
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp: In function ‘int main()’:
prog.cpp:20:16: error: ‘system’ was not declared in this scope
  system("pause");
                ^
prog.cpp: In function ‘void choice_newtime()’:
prog.cpp:56:97: warning: suggest parentheses around ‘&&’ within ‘||’ [-Wparentheses]
   if((i == 2  && ntime[i] == ':') || (i == 5 && ntime[i] == ':') || (i == 8 && ntime[i] == ',') && (count_symb <= 3))
                                                                                                 ^
prog.cpp: In function ‘void set_newtime()’:
prog.cpp:89:56: error: no matching function for call to ‘std::basic_ifstream<char>::open(std::basic_string<char>)’
  input.open("D:\\subtitles\\Release\\" + input_filename);
                                                        ^
prog.cpp:89:56: note: candidate is:
In file included from prog.cpp:2:0:
/usr/include/c++/4.8/fstream:538:7: note: void std::basic_ifstream<_CharT, _Traits>::open(const char*, std::ios_base::openmode) [with _CharT = char; _Traits = std::char_traits<char>; std::ios_base::openmode = std::_Ios_Openmode]
       open(const char* __s, ios_base::openmode __mode = ios_base::in)
       ^
/usr/include/c++/4.8/fstream:538:7: note:   no known conversion for argument 1 from ‘std::basic_string<char>’ to ‘const char*’
prog.cpp:90:58: error: no matching function for call to ‘std::basic_ofstream<char>::open(std::basic_string<char>)’
  output.open("D:\\subtitles\\Release\\" + output_filename);
                                                          ^
prog.cpp:90:58: note: candidate is:
In file included from prog.cpp:2:0:
/usr/include/c++/4.8/fstream:713:7: note: void std::basic_ofstream<_CharT, _Traits>::open(const char*, std::ios_base::openmode) [with _CharT = char; _Traits = std::char_traits<char>; std::ios_base::openmode = std::_Ios_Openmode]
       open(const char* __s,
       ^
/usr/include/c++/4.8/fstream:713:7: note:   no known conversion for argument 1 from ‘std::basic_string<char>’ to ‘const char*’
prog.cpp:96:40: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
    for(int i = 0; i < str_input.length(); i+=17)
                                        ^
prog.cpp:98:37: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int j = 0; j < ntime.length(); j++)
                                     ^
stdout
Standard output is empty