Hi,
I'm having problem with "WriteLine". What I'm tryin to do is write into the selected txt file(from openFileDialog) when user type something in the textBox.
******************************************************
My output is something wrong. For example: when I type "testing" in the textBox, what I see in my text file is as below:
t
te
tes
test
testi
testin
testing
******************************************************
kindly give me some advice if I'm wrong with the code.
private: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e)
{
openFileDialog1->ShowDialog();
StreamReader^ sr = gcnew StreamReader(openFileDialog1->FileName);
String^ textfile = sr->ReadToEnd();
sr->Close();
textBox1->Text= textfile;
}
private: System::Void textBox2_TextChanged(System::Object^ sender, System::EventArgs^ e)
{
StreamWriter^ writeToFile = File::AppendText(openFileDialog1->FileName);
//String^ fileName=openFileDialog1->FileName; //save file directory to txt file
writeToFile->WriteLine(textBox2->Text);
writeToFile->Close();
}