VC++ Stream Writer problems.
Okay I finally decided to try using actual managed code to handle my file writing since all the code where I am converting System::String to std::string and using filestreams is becoming very touchy. I decided now would be a good time to fix it but it looks like I'm just breaking things more. Anyway here is a piece of my code and it is throwing a System.IO.Exception every time it tried to close the stream writer. Any ideas?
Code:
String^ path = "c:\\MyTest.txt";
// Delete the file if it exists.
if (File::Exists(path))
File::Delete(path);
//Create the file.
FileStream^ fs = File::Create(path);
StreamWriter^ sw = gcnew StreamWriter(fs, System::Text::Encoding::ASCII);
int cnt = 0;
while (!tmp->Contains("(END)") && cnt < 30){
connector.WriteToPipe("\r");
sw->WriteLine("This is a test line\n");
tmp = gcnew String(connector.ReadFromPipe().c_str());
cnt++;
}
sw->Close();
What this would normally do write to a telnet session and readback the data until it finds (END) or has gone 30 times. the 30 times is just for my debugging write now and instead of writing tmp I am just writing a test line to make sure things are working first before I introduce more problems. I looked at 2 different tutorials on file writing with VC++ and this what I got out of it.
thanks
EDIT: okay it is this line -
Code:
tmp = gcnew String(connector.ReadFromPipe().c_str());
but I dont understand why. All connector.ReadFromPipe() does it reads in any data from a piped PuTTy telnet session. If nothing is there it returns "NULL". Why should this be messing up my streamwriter??