QgsVectorLayer* layer = new QgsVectorLayer("path/to/shapefile.shp", "layer_name", "ogr"); int featureCount = layer->featureCount();
QgsMapLayerRegistry::instance()->addMapLayer(layer); int featureCount = layer->featureCount();In this example, we add the created layer to the QGIS registry using QgsMapLayerRegistry to make it visible in the map interface, and then retrieve the feature count using featureCount function. Both examples use QgsVectorLayer::featureCount method to retrieve the number of features present in the vector layer. The package/library used in the examples is the QGIS API.