Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void FileProc(StreamReader^ sr, StreamWriter^ sw, ListBox^ lstInFile, ListBox^ lstOutFile, TextBox^ mincountTB) {
- String^ InBuffer = "";
- String^ OutBuffer = "";
- int count = 0; // Количество изменений в строке
- int mincount = 1000000; // Минимальное количество изменений
- String^ mincountString = ""; // Строка с минимальным количеством изменений
- try {
- while (InBuffer = sr->ReadLine()) {
- if (InBuffer->Length == 0) continue;
- lstInFile->Items->Add(InBuffer);
- count = 0; // Количество изменений в строке
- OutBuffer = task(InBuffer, count);
- sw->WriteLine(OutBuffer);
- lstOutFile->Items->Add(OutBuffer);
- if (count < mincount && count > 0) { // Поиск строки с минимальным количеством изменений
- mincount = count;
- mincountString = OutBuffer;
- }
- }
- if (mincountString == "") mincountString = "Изменений не было.";
- mincountTB->Text = mincountString;
- }
- catch (Exception ^ ex) {
- MessageBox::Show(ex->Message, "Ошибка", MessageBoxButtons::OK, MessageBoxIcon::Error);
- }
- }
- private: System::Void Button_Start_Click(System::Object^ sender, System::EventArgs^ e) {
- listBox_input->Items->Clear();
- listBox_output->Items->Clear();
- String^ InFile = textBox_input->Text;
- String^ OutFile = textBox_output->Text;
- StreamReader^ sr = nullptr;
- StreamWriter^ sw = nullptr;
- try {
- sr = gcnew StreamReader(InFile);
- sw = gcnew StreamWriter(OutFile, false);
- }
- catch (Exception ^ ex) {
- MessageBox::Show(ex->Message, "Ошибка", MessageBoxButtons::OK, MessageBoxIcon::Error);
- if (sr) sr->Close();
- if (sw) sw->Close();
- return;
- }
- FileProc(sr, sw, listBox_input, listBox_output, textBox_mincount);
- sr->Close();
- sw->Close();
- }
- private: System::Void Form1_Load(System::Object^ sender, System::EventArgs^ e) {
- listBox_input->Items->Clear();
- listBox_output->Items->Clear();
- textBox_input->Clear();
- textBox_output->Clear();
- button_Start->Enabled = false;
- }
- private: System::Void Button_openInput_Click(System::Object^ sender, System::EventArgs^ e) {
- OpenFileDialog^ openFileDialog = gcnew OpenFileDialog;
- openFileDialog->Title = "Открытие входногого файла";
- openFileDialog->InitialDirectory = "C:\\";
- openFileDialog->Filter = "Text files (*.txt)|*.txt";
- openFileDialog->FilterIndex = 1;
- openFileDialog->ShowReadOnly = true;
- openFileDialog->ReadOnlyChecked = true;
- openFileDialog->RestoreDirectory = true;
- if (openFileDialog->ShowDialog() == System::Windows::Forms::DialogResult::OK) textBox_input->Text = openFileDialog->FileName;
- else textBox_input->Text = "";
- button_Start->Enabled = textBox_input->Text->Length > 0 && textBox_output->Text->Length > 0;
- }
- private: System::Void Button_openOutput_Click(System::Object^ sender, System::EventArgs^ e) {
- SaveFileDialog^ saveFileDialog = gcnew SaveFileDialog;
- saveFileDialog->Title = "Открытие выходногого файла";
- saveFileDialog->Filter = "Text files (*.txt)|*.txt";
- saveFileDialog->FilterIndex = 1;
- saveFileDialog->OverwritePrompt = true;
- if (saveFileDialog->ShowDialog() == System::Windows::Forms::DialogResult::OK) textBox_output->Text = saveFileDialog->FileName;
- else textBox_input->Text = "";
- button_Start->Enabled = textBox_input->Text->Length > 0 && textBox_output->Text->Length > 0;
- }
Add Comment
Please, Sign In to add comment