#include <iostream>
#include <variant>
#include <string>
#if 0
int main() {
std::variant<int, float, std::string> v;
v = 42;
std::cout << std::get<int>(v) << std::endl; // prints 42
v = 3.14f;
std::cout << std::get<float>(v) << std::endl; // prints 3.14
v = "hello world";
std::cout << std::get<std::string>(v) << std::endl; // prints "hello world"
return 0;
}
bellow one is get if example
#endif
int main() {
std::variant<int, float, std::string> var = "hello";
if (auto value = std::get_if<std::string>(&var)) {
std::cout << "Got string: " << *value << std::endl;
} else {
std::cout << "value not a string" << std::endl;
}
return 0;
}
To embed this project on your website, copy the following code and paste it into your website's HTML: