C++ cli 如何保存字节偏移量并使用stream::seek或stream::position

C++ cli 如何保存字节偏移量并使用stream::seek或stream::position,c++-cli,C++ Cli,我有一个程序,它逐行遍历一个输入文件,将其显示在windows窗体上,然后是一个操作按钮,将结果发布到输出文件 我希望能够使用stream::seek,所以当我关闭应用程序并返回到它时,它会转到我打开的输入的最后一行,这样我就不必每次都从一开始就开始 这是我当前的代码: static System::IO::StreamReader ^fileName = nullptr; public: System::Void StartBtn_Click(System::Object^

我有一个程序,它逐行遍历一个输入文件,将其显示在windows窗体上,然后是一个操作按钮,将结果发布到输出文件

我希望能够使用stream::seek,所以当我关闭应用程序并返回到它时,它会转到我打开的输入的最后一行,这样我就不必每次都从一开始就开始

这是我当前的代码:

static System::IO::StreamReader ^fileName = nullptr;   


    public: System::Void StartBtn_Click(System::Object^  sender, System::EventArgs^  e) {
count++;

if (count == 1)
{
                textBox1->Text="";
                textBox2->Text="";
                textBox3->Text="";
                textBox4->Text="";
                textBox5->Text="";
if (fileName == nullptr)

        fileName = gcnew System::IO::StreamReader (textBox6->Text);



 if (!fileName->EndOfStream)
 {
  String^ delimStr = ",";

   array<Char>^ delimiter = delimStr->ToCharArray( );
   array<String^>^ words;
   String^ str = fileName->ReadLine();


words = str->Split( delimiter );



     textBox1->Text += gcnew String (words[10]);


     textBox2->Text += gcnew String (words[21]);

     textBox3->Text += gcnew String (words[49]);

     textBox4->Text += gcnew String (words[0]);

     textBox5->Text += gcnew String (words[28]);




 }
}
 else 
 {
                textBox1->Text="";
                textBox2->Text="";
                textBox3->Text="";
                textBox4->Text="";
                textBox5->Text="";
if (fileName == nullptr)
        fileName = gcnew System::IO::StreamReader (textBox6->Text);



 if (!fileName->EndOfStream)
 {
   String^ delimStr = ",";

   array<Char>^ delimiter = delimStr->ToCharArray( );
   array<String^>^ words;
   String^ str = fileName->ReadLine();


   words = str->Split( delimiter );




     textBox1->Text += gcnew String (words[10]);


     textBox2->Text += gcnew String (words[21]);

     textBox3->Text += gcnew String (words[49]);

     textBox4->Text += gcnew String (words[0]);

     textBox5->Text += gcnew String (words[28]);



String^ fileName1 = nullptr;
                 System::String^ finaladdress = textBox1->Text; 

                 System::String^ correctString = finaladdress->Replace( "\r\n", "," );

                 System::String^ finaladdress2 = textBox2->Text;    

                 System::String^ correctString2 = finaladdress2->Replace( "\r\n", "," );

                 System::String^ finaladdress3 = textBox3->Text;    

                 System::String^ correctString3 = finaladdress3->Replace( "\r\n", "," );

                 System::String^ Action = ReqActBox->SelectedItem->ToString();

                 System::String^ warnings = textBox4->Text;
        System::String^ correctString4 = warnings->Replace( "\r\n", "," );

                 System::String^ warnings1 = textBox5->Text;
        System::String^ correctString5 = warnings1->Replace( "\r\n", "," );

                 fileName1 += "C:\\MergeData\\output.txt";
                 StreamWriter^ sw = gcnew StreamWriter(fileName1, true);


      sw->Write(gcnew String ("\r\n"));              
      sw->Write(gcnew String (words[4]));
      sw->Write(gcnew String (","));
      sw->Write(Action);
      sw->Write(gcnew String (","));

      sw->Write(correctString);
      sw->Write(gcnew String (","));
          sw->Write(correctString4);
      sw->Write(gcnew String (","));
          sw->Write(correctString2);
          sw->Write(gcnew String (","));
      sw->Write(correctString5);
      sw->Write(gcnew String (","));
          sw->Write(correctString3);

          sw->Close();


 }

   }


}


private: System::Void button1_Click(System::Object^  sender, System::EventArgs^  e) {

   System::String^ paf = textBox6->Text;
  OpenFileDialog^ sfd = gcnew OpenFileDialog();

            if( sfd->ShowDialog() == System::Windows::Forms::DialogResult::OK )
            {
                paf = sfd->FileName;
            }


    textBox6->Text = paf;

Stream::Position属性值对于文本流没有意义。它将远远领先于您实际阅读的行,StreamReader需要提前阅读以处理可变长度编码和行尾。停止使用文本文件,这是保存数据最糟糕的方式。我应该使用什么文件来代替?