我已经在线阅读了很多关于读写的内容,但却是另一个有多个文本框的故事。
private: System::Void saveToolStripMenuItem_Click(System::Object^ sender, System::EventArgs^ e) {
SaveFileDialog ^ Save_file = gcnew SaveFileDialog();
Save_file->Title = "Save your Character sheet";
Save_file->Filter ="Text file|*.txt";
Save_file->ShowDialog();
if (Save_file->FileName != "")
{
System::IO::StreamWriter^ sv = gcnew System::IO::StreamWriter(Save_file->OpenFile());
sv->WriteLine(Character_Nameinput + "\n");
sv->WriteLine(Char_Descinput + "\n");
sv->WriteLine(Stand_nameinput + "\n");
sv->WriteLine(Stand_descinput + "\n");
sv->WriteLine(Goals_input + "\n");
sv->WriteLine(Impulses_input + "\n");
sv->WriteLine(Notes_input + "\n");
sv->Close();
MessageBox::Show("Your character has been saved.");
}
}
这是我保存活动的一大块。有更多的文本框,但它是不需要的信息,因为它对于每个框基本相同。
**private: System::Void fileToolStripMenuItem_Click(System::Object^ sender, System::EventArgs^ e) {
OpenFileDialog ^ Load_file = gcnew OpenFileDialog();
Load_file->Title = "Load a Character sheet";
Load_file->Filter = "Text file|*.txt";
Load_file->ShowDialog();
if (Load_file->FileName != "")
{
System::IO::StreamReader^ ld = gcnew System::IO::StreamReader(Load_file->OpenFile());
Character_Nameinput->Text = ld->ReadToEnd();
ld->Close();
}
}
这是我到目前为止所拥有的。它将整个文件加载到第一个文本框中我想知道它们是更好的方式还是我如何分离文本文件?