You can convert the "any" type to a string by testing for all existing types (e.g. int, string, float, etc.) using the typeid() function.
- value.type() : will return the type of the value.
- typeid(float) : will return the id of a float type value.
To put all this together, we can create a function that tests all the types possible and then convert the value to a string depending on its type.
Here is the complete solution :
#include<any>
        
std::any variable;
std::string anyToString = anyToString(variable);
    
string anyToString(any value) {
    
        //add whatever types you would like as an if condition
        if(value.type() == typeid(string))
            return std::any_cast<string> (value);
    
        if (value.type() == typeid(float))
            return to_string(std::any_cast<float> (value));
    
        if (value.type() == typeid(int))
            return to_string(std::any_cast<int> (value));
}