views:

22

answers:

1

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) );

             Application::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

+1  A: 

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();
Alex Farber
isn't this a c code not a c++ code ?
Ramiz Toma
This is C++/CLI, exactly like the code you have posted.
Alex Farber
well thank you very much it solved it i just added a ^ where yu declared sw in line one thanks!
Ramiz Toma
sir do you know how to close the window and open new one when the button is clicked?
Ramiz Toma