#include#include using namespace std; int main() { boost::variant v = 100; string str = boost::get (v); //Convert variant type to string cout<
In this example, we create a variant type that can accept both integer and string data types. The variant is assigned an integer value of 100. We then use the toString method to convert the variant type to a string and store it in a string variable. Finally, we print the string value.
Example 2:#include#include #include using namespace std; int main() { boost::variant v = 3.14; string str = boost::get (v); //Convert variant type to string cout< In this example, we create a variant type that can accept both integer and double data types. The variant is assigned a double value of 3.14. We then use the toString method to convert the variant type to a string and store it in a string variable. Finally, we print the string value. Package library: Boost C++ Library.