ARRAYS

A

Anotherpostal

NEED HELP INCREASING CAPACITY OF ARRAY FOR SEARCHING AND FINdING AND
ADDING MULTIPLE COMPONENTS (like in struct)

===================================================================================
void AddtoArray(vector<String>&Array,const String & ValtoAdd)
{
Array.resize(Array.length()+1);
Array[Array.length()-1]=ValtoAdd;
}
 
V

velthuijsen

1) Disable the caps lock key (at least while posting).

2) Unless you are not using the stl vector or if you are and not
limited in the amount of memory that is available remove the function
and use .pushback(value) on the vector you are passing to this function.
 
R

Rolf Magnus

NEED HELP INCREASING CAPACITY OF ARRAY FOR SEARCHING AND FINdING AND
ADDING MULTIPLE COMPONENTS (like in struct)

PLEASE DON'T SHOUT! Thank you.

===================================================================================
void AddtoArray(vector<String>&Array,const String & ValtoAdd)
{
Array.resize(Array.length()+1);
Array[Array.length()-1]=ValtoAdd;
}

Ah, so by "array" you actually mean std::vector. Anyway, your function could
be simpler written as:

void AddtoArray(vector<String>&Array,const String & ValtoAdd)
{
Array.push_back(ValtoAdd);
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,206
Messages
2,571,069
Members
47,675
Latest member
KevinStepp

Latest Threads

Top