473,385 Members | 1,555 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Array To Vector Conversion


I am wondering if there is a short way (i.e. one liner) to convert an
array into a list, vector etc. in c++.

Dec 25 '07 #1
3 6813
D. Susman wrote:

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<intV(arr, arr + sizeof(arr)/sizeof(int));
Dec 25 '07 #2
- 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 helps.

Ambar Shukla.
On Dec 25, 11:45 am, "D. Susman" <derya.sus...@gmail.comwrote:

I am wondering if there is a short way (i.e. one liner) to convert an
array into a list, vector etc. in c++.

Dec 25 '07 #3
On 2007-12-25 05:45:21 -0600, "D. Susman" <de**********@gmail.comsaid:

I am wondering if there is a short way (i.e. one liner) to convert an
array into a list, vector etc. in c++.

You can also use boost::array, which provides STL iterator semantics to
a plain old C array.


Dec 25 '07 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

by: Jeff Williams | last post by:
Ok, everyone loves to talk about dynamic arrays and ptr's etc, they provide endless conversation :) so here goes: Will this leak memory (my intuition says yes): void foo(vector<int*>& vec) {...
by: Ruediger Knoerig | last post by:
In my current project I used templates to provide an universial interface to vector objects. For this purpose I declared two methods with an additional template argument: template<class Vector>...
by: James | last post by:
Hi, I'm hoping someone can help me out. If I declare a class, eg. class CSomeclass { public: var/func etc..... private varfunc etc..
by: James Daughtry | last post by:
char array; scanf("%19s", &array); I know this is wrong because it's a type mismatch, where scanf expects a pointer to char and gets a pointer to an array of 20 char. I know that question 6.12...
by: Mateo | last post by:
I have char *array and it is dinamically alocated.... When I pass it to other function, I need to determine size of this array.... Problem: sizeof operator does not work with dinamically alocated...
by: Sudzzz | last post by:
Hi, I'm trying to convert a string something like this "{201,23,240,56,23,45,34,23}" into an array in C++ Please help. Thanks, Sudzzz
by: mike3 | last post by:
Hi. I can't believe I may have to use an array here. I've got this bignum package I was making in C++ for a fractal generator, and tried an approach that was suggested to me here a while...
by: Slain | last post by:
I have more of a conceptual question now. Let us say I do this:- char *str; --create an array of pointers str= "John"; I thought this would automatically put John at some memory space and...
by: Edward Jensen | last post by:
Hi, I have the following static arrays of different size in a class: in header: static double w2, x2; static double w3, x3; static double w4, x4; in GaussLegendre.cpp:
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.