Advertisement
kirya_shkolnik

openFileMatr Nikita

Nov 8th, 2021
1,655
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.49 KB | None | 0 0
  1.        void openFileMatr(TextBox^ inp, TextBox^ filename) { // открытие файла для матрицы
  2.            OpenFileDialog^ openFileDialog = gcnew OpenFileDialog;
  3.            openFileDialog->Title = "Открытие входногого файла";
  4.            openFileDialog->InitialDirectory = "C:\\";
  5.            openFileDialog->Filter = "Текстовый файл (*.txt)|*.txt";
  6.            openFileDialog->FilterIndex = 1;
  7.            openFileDialog->ShowReadOnly = true;
  8.            openFileDialog->ReadOnlyChecked = true;
  9.            openFileDialog->RestoreDirectory = true;
  10.            if (openFileDialog->ShowDialog() == System::Windows::Forms::DialogResult::OK) {
  11.                filename->Text = openFileDialog->FileName;
  12.                try {
  13.                    StreamReader^ sr = gcnew StreamReader(openFileDialog->FileName);
  14.                    String^ InBuffer = "";
  15.                    String^ outputtext = "";
  16.                    while (InBuffer = sr->ReadLine()) {
  17.                        if (InBuffer->Length == 0) continue; // Если строка пустая пропустить
  18.                        outputtext += InBuffer; //Собираем строки из входного файла в одну строку
  19.                        outputtext += "\n";
  20.                    }
  21.                    inp->Text = outputtext; // Записываем полученную строку в техктбокс
  22.                    if (sr) sr->Close();
  23.                }
  24.                catch (Exception ^ ex) {
  25.                    MessageBox::Show(ex->Message, "Ошибка", MessageBoxButtons::OK, MessageBoxIcon::Error);
  26.                    return;
  27.                }
  28.            }
  29.            else {
  30.                filename->Text = "";
  31.            }
  32.        }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement