开发者

vc++ forms designer

开发者 https://www.devze.com 2023-01-11 03:15 出处:网络
im using vc++ forms. i created a textbox, im trying to get the value in it i used textBox1->Text. all im trying to do is this create a file name text.txt than write in side the file what is inside the

im using vc++ forms. i created a textbox, im trying to get the value in it i used textBox1->Text. all im trying to do is this create a file name text.txt than write in side the file what is inside the textBox1. here the code

private: System::Void button1_Click(System::Object^  sender, System::EventArgs^  e) {
             Help::ShowPopup( button1, textBox1->Text , Point(button1->Right,this->button1->Bottom) );//works here
             ofstream a_file("test.txt");
             a_file << textBox1->Text;//get error
             a_file.close();
             if ( !a_file.is_open() )
                Help::ShowPopup( button1, "s" , Point(button1->Right,this->button1->Bottom) );

             A开发者_运维知识库pplication::Exit;
         }

the error is this error C2679: binary '<<' : no operator found which takes a right-hand operand of type 'System::String ^' (or there is no acceptable conversion) thanks in advance rami


Don't mix managed and unmanaged types unless this is absolutely necessary. Replace unmanaged ofstream with managed StreamWriter:

System::IO::StreamWriter sw = gcnew System::IO::StreamWriter(L"test.txt");
sw->WriteLine(textBox1->Text);
sw->Close();
0

精彩评论

暂无评论...
验证码 换一张
取 消