Using .length returns incorrect number of elements
QueenSvetlana
svetlanalilyrosemond at gmail.com
Sun Aug 19 15:44:07 UTC 2018
When using the .length property of a dynamic array why does it
return the incorrect number of elements after I use the appender?
import std.stdio;
import std.array : appender;
void main()
{
//declaring a dynamic array
int [] arrayofNumbers;
//append an element using the ~= syntax
arrayofNumbers ~= 1;
arrayofNumbers ~= 2;
//print the array
writeln(arrayofNumbers);
//Using appender
auto appendNumber = appender(arrayofNumbers);
appendNumber.put(10);
writeln(appendNumber.data);
writeln(arrayofNumbers.length);
}
Output:
[1, 2]
[1, 2, 10]
2 --- > Should be 3
More information about the Digitalmars-d-learn
mailing list