Create StreamWriter from file name : StreamWriter « File Directory « Visual C++ .NET






Create StreamWriter from file name

 
#include "stdafx.h"
using namespace System;
using namespace System::IO;

int main()
{

   StreamWriter^ sw = gcnew StreamWriter("textfile.txt");
   sw->WriteLine("asdf");
   sw->Flush();
   sw->Close();

   StreamWriter^ sw2 = File::CreateText("newtextfile.txt");

   StreamReader^ sr = gcnew StreamReader("textfile.txt");
   String^ line;
   while ((line = sr->ReadLine()) != nullptr)
   {
      Console::WriteLine(line);
   }
}

   
  








Related examples in the same category

1.Write to a text file with StreamWriter
2.Read a text file with StreamReader
3.Read text file to the end
4.Write line to text file with StreamWriter