Search
 
SCRIPT & CODE EXAMPLE
 

CPP

delete 2d dynamic array c++

for (int i = 0; i < numRows; i++) {
    delete [] world[i];
//    world[i] = 0;  // <- don't have to do this
}
delete [] world;  // <- because they won't exist anymore after this
world = 0;
Comment

delete specific row from dynamic 2d array c++

string** new_array = array;
for(int i=0; i<numRows; i++){
  new_array = new string[coloumns]
    if(i != n){ // <- if you want to delete nth row then
        new_array[i] = array[i];
    }
}
array = new_array; // <- now array excluding nth row is saved in this pointer.
Comment

new and delete 2D array

// let's say we want to dynamically make int[Y][X]:
int** superevil = new int*[Y];
for(int i = 0; i < Y; ++i)
  superevil[i] = new int[X];

// now we can do this:
superevil[2][3] = 1;

// but cleanup is just as ugly as allocation:
for(int i = 0; i < Y; ++i)
  delete[] superevil[i];
delete[] superevil;
Comment

PREVIOUS NEXT
Code Example
Cpp :: c++ throw exception 
Cpp :: prints all the keys and values in a map c++ 
Cpp :: c++ default array value not null 
Cpp :: how to output to console c++ 
Cpp :: stl for sorting in c++ 
Cpp :: read variable to file cpp 
Cpp :: c++ rand() 
Cpp :: shout sharkest 
Cpp :: c++ remove whitespace from string and keep the same size 
Cpp :: taking input from user in array in c++ 
Cpp :: number to binary string c++ 
Cpp :: user defined key for map in c++ 
Cpp :: go through std vector 
Cpp :: stack implementation using linked list in cpp 
Cpp :: rank() in c++ 
Cpp :: priority queue c++ type of pairs 
Cpp :: c++ round number up 
Cpp :: cpp merge two sets 
Cpp :: string input with space c++ stl 
Cpp :: qt popup window 
Cpp :: c++ get time 
Cpp :: how to open and read text files in c++ 
Cpp :: C++ switch - case - break 
Cpp :: c++ typedef 
Cpp :: c++ return multiple values 
Cpp :: c++ int main() 
Cpp :: find in string c++ 
Cpp :: c++ enum 
Cpp :: c++ Program for Sum of the digits of a given number 
Cpp :: c++ vector move element to front 
ADD CONTENT
Topic
Content
Source link
Name
9+9 =