How cout vector variant?

  Kiến thức lập trình

Hello i have tried to cout vector as a variant<int,char> but I can’t any solves?
This is my code



#include "iostream"

#include "vector"

#include "variant"

using namespace std;



int main(int argc, char *argv[])

{

    vector<variant<int,char>> numbers = {1,2,3,4,'a'};

    for (const auto &i: numbers){

        cout << i;

    }

}

I try to cout it as pointers and it’s not worked when I make it with one type variable it work but with “auto” isn’t work

New contributor

Opo Bot is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

LEAVE A COMMENT