Tell me how to read data from a file. I read that it’s written about the dialogue on MSDN, but it doesn’t say exactly how to read the data.
Wrote like this:
{ Stream^ myStream; if(openFileDialog1->ShowDialog() == System::Windows::Forms::DialogResult::OK) { if((myStream = openFileDialog1->OpenFile()) != nullptr) { StreamReader^ sw = gcnew StreamReader(this->openFileDialog1->FileName); a = sw->Read(); b = sw->Read(); h = sw->Read(); String^ s = "Левая граница: " + System::Convert::ToString(a) + "\n" + "Правая граница: " + System::Convert::ToString(b) + "\n" "Шаг: " + System::Convert::ToString(h) + "\n" "Ответ: "; for(float x = a; x < b; x += h) { if(x * x - sin(3 * x * 3.14159265 / 180) <= 0.00001) s += System::Convert::ToString(int(x + 0.5)); } MessageBox::Show(s, "Результат"); myStream->Close(); sw->Close(); } } } But instead of the desired result (the file contains -2 0 2 ), I get the values 45 50 32 .
I tried different file encodings (ANSI, UTF-8).