MC++ writing to file

Started by
1 comment, last by Eriond 19 years, 11 months ago
I'm trying to write to a file like this (translated from a C# example):
#using <mscorlib.dll>
using namespace System;
using namespace System::IO;
using namespace System::Text;

int main()
{
	try
	{
		FileStream *file = new FileStream(S"test.txt", FileMode::OpenOrCreate);
		StreamWriter *sw = new StreamWriter(file);
		sw->WriteLine(S"Hello World!");
		sw->Write(S"This is a ");
		sw->WriteLine(S"string of characters.");
	}
	catch (IOException *e)
	{
		Console::WriteLine("An IO exception has been thrown!");
		Console::WriteLine(e->ToString());
		Console::ReadLine();
		return 1;
	}
	return 0;
}
The program compiles fine, and when I run it, without the file existing, it gets created but nothing is written to it [edited by - Eriond on May 18, 2004 4:48:22 PM]
Advertisement
Try putting a sw->Close(); after your writes. It sounds like your file isn''t getting flushed.
That fixed it, thank you very much.

This topic is closed to new replies.

Advertisement