CPLString str = "Hello"; if (str.empty()) { printf("The string is empty\n"); } else { printf("The string has %d characters\n", str.size()); }
CPLString str; if (str.empty()) { str = "World"; } printf("The string is %s\n", str.c_str());In this example, we create an empty CPLString object and use the empty() method to check its emptiness. Since the string is indeed empty, we assign the string "World" to it. The c_str() method is used to retrieve a const char* representation of the string, which is then printed to the console. The output of this code is "The string is World". Package/library: GDAL (Geospatial Data Abstraction Library)