Thread overview | |||||
---|---|---|---|---|---|
|
March 26, 2004 [Beginner] How to add elements to a dynamic array? | ||||
---|---|---|---|---|
| ||||
I want to build an array dynamically, similar to std::vector in C++ :
std::vector<int> v;
v.push_back(1);
v.push_back(2);
v.push_back(3);
Can this be done with D arrays?
--
dave
|
March 26, 2004 Re: [Beginner] How to add elements to a dynamic array? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Dave Sieber | int[] v; v ~= 1; v ~= 2; v ~= 3; "Dave Sieber" <dsieber@spamnot.sbcglobal.net> wrote in message news:Xns94B860C93E900dsiebersbc@63.105.9.61... > I want to build an array dynamically, similar to std::vector in C++ : > > std::vector<int> v; > v.push_back(1); > v.push_back(2); > v.push_back(3); > > Can this be done with D arrays? > > -- > dave |
March 26, 2004 Re: [Beginner] How to add elements to a dynamic array? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Ivan Senji | "Ivan Senji" <ivan.senji@public.srce.hr> wrote: > int[] v; > v ~= 1; > v ~= 2; > v ~= 3; Thank you, Ivan. I had seen this notation in the docs, but the doc said it was for array concatenation. In my case, I wanted to add a single element, not another array, so I assumed it was not the correct way. IAC, it compiles with your suggested notation. Now, to test it... :-) -- dave |
Copyright © 1999-2021 by the D Language Foundation