aplikację utworzyłem w Visyal C++ 2005
po uruchomieniu programu działa button1 - tworzy plik.txt, a po naciśnięciu button2 powinien wpisać liczby do texBox1, niestety zamyka się program i wyskakuje okno dialogowe "Microsoft Visual Studio" z następującym tekstem:
An unhandled exception of type 'System.ArgumentException' occurred in mscorlib.dll
Additional information: The output char buffer is too small to contain the
decoded characters, encoding 'Unicode (UTF-8)' fallback
'System.Text.DecoderReplacementFallback'.
a na dole ekranu Visual C++2005, w oknie "Call Stack" jest podświetlona linia:
Test 67.exe!Test67::Form1::button2_Click(System::Object^ sender = 0x0012ed38, System::EventArgs^ e = 0x0012ed44) Line 129 + 0x8 bytes C++
w oknie "Debug" są następujące zapisy:
'Test 67.exe' (Managed): Loaded 'D:\WINDOWS\assembly\GAC_32\mscorlib\2.0.0.0__b77a5c561934e089\mscorlib.dll', No symbols loaded.
'Test 67.exe' (Managed): Loaded 'd:\cc8\test 67\debug\Test 67.exe', Symbols loaded.
'Test 67.exe' (Managed): Loaded 'D:\WINDOWS\WinSxS\x86_Microsoft.VC80.DebugCRT_1fc8b3b9a1e18e3b_8.0.50727.42_x-ww_f75eb16c\msvcm80d.dll', Symbols loaded.
'Test 67.exe' (Managed): Loaded 'D:\WINDOWS\assembly\GAC_MSIL\System\2.0.0.0__b77a5c561934e089\System.dll', No symbols loaded.
'Test 67.exe' (Managed): Loaded 'D:\WINDOWS\assembly\GAC_MSIL\System.Windows.Forms\2.0.0.0__b77a5c561934e089\System.Windows.Forms.dll', No symbols loaded.
'Test 67.exe' (Managed): Loaded 'D:\WINDOWS\assembly\GAC_MSIL\System.Drawing\2.0.0.0__b03f5f7f11d50a3a\System.Drawing.dll', No symbols loaded.
A first chance exception of type 'System.ArgumentException' occurred in mscorlib.dll
A first chance exception of type 'System.ArgumentException' occurred in mscorlib.dll
An unhandled exception of type 'System.ArgumentException' occurred in mscorlib.dll
Additional information: The output char buffer is too small to contain the decoded characters, encoding 'Unicode (UTF-8)' fallback 'System.Text.DecoderReplacementFallback'.
The program '[3528] Test 67.exe: Managed' has exited with code -532459699 (0xe0434f4d).
plik Form1.h
#pragma once
namespace Test67 {
using namespace System;
using namespace System::ComponentModel;
using namespace System::Collections;
using namespace System::Windows::Forms;
using namespace System::Data;
using namespace System::Drawing;
using namespace System::IO; public ref class Form1
: public System::Windows::Forms::Form
{
public:
Form1( void )
{
InitializeComponent();
}
protected:
~Form1()
{
if( components )
{
delete components;
}
}
private: System::Windows::Forms::Button ^ button1;
private: System::Windows::Forms::Button ^ button2;
private: System::Windows::Forms::TextBox ^ textBox1;
protected:
private:
System::ComponentModel::Container ^ components;
#pragma region Windows Form Designer generated code
void InitializeComponent( void )
{
this->button1 =( gcnew System::Windows::Forms::Button() );
this->button2 =( gcnew System::Windows::Forms::Button() );
this->textBox1 =( gcnew System::Windows::Forms::TextBox() );
this->SuspendLayout();
this->button1->Location = System::Drawing::Point( 21, 188 );
this->button1->Name = L"button1";
this->button1->Size = System::Drawing::Size( 65, 66 );
this->button1->TabIndex = 0;
this->button1->Text = L"Zapis do pliku";
this->button1->UseVisualStyleBackColor = true;
this->button1->Click += gcnew System::EventHandler( this, & Form1::button1_Click );
this->button2->Location = System::Drawing::Point( 113, 188 );
this->button2->Name = L"button2";
this->button2->Size = System::Drawing::Size( 75, 66 );
this->button2->TabIndex = 1;
this->button2->Text = L"Odczyt z pliku";
this->button2->UseVisualStyleBackColor = true;
this->button2->Click += gcnew System::EventHandler( this, & Form1::button2_Click );
this->textBox1->Location = System::Drawing::Point( 15, 15 );
this->textBox1->Multiline = true;
this->textBox1->Name = L"textBox1";
this->textBox1->Size = System::Drawing::Size( 250, 150 );
this->textBox1->TabIndex = 2;
this->AutoScaleDimensions = System::Drawing::SizeF( 6, 13 );
this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
this->ClientSize = System::Drawing::Size( 292, 266 );
this->Controls->Add( this->textBox1 );
this->Controls->Add( this->button2 );
this->Controls->Add( this->button1 );
this->Name = L"Form1";
this->Text = L"Form1";
this->ResumeLayout( false );
this->PerformLayout();
}
#pragma endregion
private: System::Void button1_Click( System::Object ^ sender, System::EventArgs ^ e )
{
System::Single liczba_single;
FileStream ^ plik_zap = File::Create( "C:\\Plik1.txt" );
BinaryWriter ^ plik_dane_zap = gcnew BinaryWriter( plik_zap );
liczba_single = 123.45;
plik_dane_zap->Write( liczba_single );
liczba_single = 456.78;
plik_dane_zap->Write( liczba_single );
liczba_single = 987.34;
plik_dane_zap->Write( liczba_single );
plik_zap->Close();
}
private: System::Void button2_Click( System::Object ^ sender, System::EventArgs ^ e )
{
System::Single liczba_single;
FileStream ^ plik_odcz = File::OpenRead( "C:\\Plik1.txt" );
BinaryReader ^ plik_dane_odcz = gcnew BinaryReader( plik_odcz );
while( plik_dane_odcz->PeekChar() != - 1 )
{
liczba_single = plik_dane_odcz->ReadSingle();
textBox1->AppendText( liczba_single.ToString() + System::Environment::NewLine );
}
plik_odcz->Close();
}
};
}
Proszę o pomoc