MStringArray colors; colors.append("red"); colors.append("green"); colors.append("blue"); cout << colors.length() << endl; // Output: 3
MStringArray fruits; cout << fruits.length() << endl; // Output: 0In this example, we create an empty MStringArray called fruits. Then we use the length method to determine the number of elements in the array, which is 0. The MStringArray class is provided by the Autodesk Maya C++ API library.