CPP
cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#include<variant>
#include <iostream>
using namespace std;
//defining Mixed struct
typedef struct{
char c{};
int i{};
double d{};
string s{};
}Mixed;
//overload << operator for Mixed cout
ostream& operator<<(ostream& os, Mixed const& m){
if(m.i) return os << m.i;
else if(m.d) return os << m.d;
else if(m.c) return os << m.c;
else if(m.s!="") return os << m.s;
return os;
}
int main() {
//using the struct Mixed
Mixed a,b,c,d;
a.c = 'x';
b.s = "install";
c.d = 9.99;
Enter to Rename, Shift+Enter to Preview
OUTPUT
Run