title: Searching a line by its text and deleting it on a textfile (From C# to C++/CLI)
body: <p>I would like to know how can I search a line by its text on a textfile and delete it. After looking at this topic--><a href="https://stackoverflow.com/questions/1245243/delete-specific-line-from-a-text-file">Delete specific line from a text file?</a> I found out this code in C#:</p>
  
  <pre><code>string line = null;
  string line_to_delete = "the line i want to delete";
  
  using (StreamReader reader = new StreamReader("C:\\input")) {
      using (StreamWriter writer = new StreamWriter("C:\\output")) {
          while ((line = reader.ReadLine()) != null) {
              if (String.Compare(line, line_to_delete) == 0)
                  continue;
  
              writer.WriteLine(line);
          }
      }
  }
  </code></pre>
  
  <p>I tried to convert it to something like this in C++/CLI:</p>
  
  <pre><code>System::String^ txtfile = L"C:\\Users\\acer\\Desktop\\aaa.txt";
   String^ line = nullptr;
   String^ line_to_delete = "dasdasdasda";
  
                      using (StreamReader ^reader = gcnew StreamReader(gcnew String(txtfile)) {
                          using (StreamWriter ^writer = gcnew StreamWriter(gcnew String(txtfile),true) {
                           while ((line == reader-&gt;ReadLine()) != nullptr) {
                              if (String.Compare(line, line_to_delete) == 0)
                              continue;
  
                      writer-&gt;WriteLine(line);
              }
          }
      }
  </code></pre>
  
  <p>but since I'm still a newbie I didn't do it right. Please notice that I did not create any temporary file, I just want to read my textfile, detect the line that says "dasdasdasda" and delete it. Can someone tell what I did wrong when converting from C# to C++/CLI?</p>