How do i do that?

This is what i was trying to do:
What is wrong with my code?

if(openFileDialog1->ShowDialog() == System::Windows::Forms:ialogResult::OK)
{

String^ path = System::IO::Path::GetDirectoryName(openFileDialog1->FileName);

fstream File;

File.open("c:\\path.txt", ios:ut);

if (File.is_open ())
{
for (int i = 0; i <= 50; i++)
File<< path[i] << endl;
}

File.close();

}


I get the error:

An unhandled exception of type 'System.IndexOutOfRangeException' occurred in myapp.exe
Additional information: Index out of limits for the matrix