59 lines
1.1 KiB
Markdown
59 lines
1.1 KiB
Markdown
# Insert
|
||||
|
|
|
|||
|
|
Inserts an element to the specified position in the array.
|
|||
|
|
|
|||
|
|
```
|
|||
|
|
bool Insert(
|
|||
|
|
string element, // element to insert
|
|||
|
|
int pos // position
|
|||
|
|
)
|
|||
|
|
|
|||
|
|
```
|
|||
|
|
|
|||
|
|
Parameters
|
|||
|
|
|
|||
|
|
element
|
|||
|
|
|
|||
|
|
[in] Value of the element to be inserted into an array
|
|||
|
|
|
|||
|
|
pos
|
|||
|
|
|
|||
|
|
[in] Position in the array to insert
|
|||
|
|
|
|||
|
|
Return Value
|
|||
|
|
|
|||
|
|
true - successful, false - cannot insert the element.
|
|||
|
|
|
|||
|
|
Example:
|
|||
|
|
|
|||
|
|
```
|
|||
|
|
//--- example for CArrayString::Insert(string,int)
|
|||
|
|
#include <Arrays\ArrayString.mqh>
|
|||
|
|
//---
|
|||
|
|
void OnStart()
|
|||
|
|
{
|
|||
|
|
CArrayString *array=new CArrayString;
|
|||
|
|
//---
|
|||
|
|
if(array==NULL)
|
|||
|
|
{
|
|||
|
|
printf("Object create error");
|
|||
|
|
return;
|
|||
|
|
}
|
|||
|
|
//--- insert elements
|
|||
|
|
for(int i=0;i<100;i++)
|
|||
|
|
{
|
|||
|
|
if(!array.Insert(IntegerToString(i),0))
|
|||
|
|
{
|
|||
|
|
printf("Insert error");
|
|||
|
|
delete array;
|
|||
|
|
return;
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
//--- use array
|
|||
|
|
//--- . . .
|
|||
|
|
//--- delete array
|
|||
|
|
delete array;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
```
|