I need to add single int
to array of int
s. How can I do it with D?
void main()
{
int v = 2;
int [] x ~= v; // do not work
}
Working code:
int v = 2;
int [] x;
x ~= v;
If you want to add a single int to an existing array, you must declare the array first:
int[] x;
x ~= 2;
You can also initialize the array with a single int:
int[] x = [2];