Appending char[] to char[][] has unexpected results

Tim Keating mrtact at gmail.com
Tue Apr 30 20:54:22 PDT 2013


Not sure whether this is a bug, or perhaps I'm misunderstanding 
something, but it seems like this should work:

void main()
{
	char[][] outBuf;
	auto f = File("testData.txt", "r");
	char[] buf;

	writeln("\n**** RAW OUTPUT *****");

	while (f.readln(buf))
	{
		write(buf);
		outBuf ~= buf;
	}

	writeln("\n**** BUFFERED OUTPUT *****");

	foreach (line; outBuf)
	{
		write(line);
	}
}

testData.txt is just a couple of lines of miscellaneous text. The 
expectation is that the raw output and the buffered output should 
be exactly the same... but they are not. (If anyone would like to 
see this for themselves, I stuck it in github: 
https://github.com/MrTact/CharBug.)

Changing the types of outBuf and buf to dchar works as expected. 
Changing outBuf to a string[] and appending buf.idup does as well.


More information about the Digitalmars-d mailing list