|
|
|
#1 |
|
Messages: n/a
Hébergeur: |
Hi,
I am wondering if there is a short way (i.e. one liner) to convert an array into a list, vector etc. in c++. Thanks. |
|
|
|
#2 |
|
Messages: n/a
Hébergeur: |
D. Susman wrote:
> Hi, > > I am wondering if there is a short way (i.e. one liner) to convert an > array into a list, vector etc. in c++. > STL Containers all have constructor Container(Iterator first, Iterator last, extra default parameters) take std::vector for example, you can write int arr[] = {1, 2, 3, 4, 5}; std::vector<int> V(arr, arr + sizeof(arr)/sizeof(int)); |
|
|
|
#3 |
|
Messages: n/a
Hébergeur: |
Assuming
- your vector is named a - the array is named a - the size of the array is s , one option would be: v.assign(a, a + s); Hope this s. Cheers, Ambar Shukla. On Dec 25, 11:45 am, "D. Susman" <derya.sus...@gmail.com> wrote: > Hi, > > I am wondering if there is a short way (i.e. one liner) to convert an > array into a list, vector etc. in c++. > > Thanks. |
|
|
|
#4 |
|
Messages: n/a
Hébergeur: |
On 2007-12-25 05:45:21 -0600, "D. Susman" <derya.susman@gmail.com> said:
> Hi, > > I am wondering if there is a short way (i.e. one liner) to convert an > array into a list, vector etc. in c++. > > Thanks. You can also use boost::array, which provides STL iterator semantics to a plain old C array. -dr |
|
![]() |
| Outils de la discussion | |
|
|