Home > Mobile >  Adding new item in C array
Adding new item in C array

Time:10-06

I am pretty new to c and was trying to add a new string in C array. In Python we can add new items by .append(). Is there any function like this in C ?

CodePudding user response:

in C arrays are of a static size. I would recommend including the vector header and replacing the array with a std::vector. vector has a function to add a new entry

CodePudding user response:

// Declaring Vector of String type
// Values can be added here using initializer-list syntax
std::vector<std::string> colour {"Blue", "Red", "Orange"};

// Strings can be added at any time with push_back
colour.push_back("Yellow");

https://www.geeksforgeeks.org/array-strings-c-3-different-ways-create/

  • Related