Advertisement
Ginsutime

std::any c++

Feb 13th, 2022
1,055
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.37 KB | None | 0 0
  1. #include <iostream>
  2. #include <any>
  3.  
  4. int main()
  5. {
  6.     std::any data;
  7.     data = 2;
  8.     data = "Cherno";
  9.     data = std::string("Cherno");
  10.  
  11.     //Have to know which type it is and then cast it into the type
  12.     //Will throw an exception (bad any cast exception) if the data is not of the type you're casting to
  13.     std::string string = std::any_cast<std::string>(data);
  14.  
  15.     std::cin.get();
  16. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement