I've written a simple program in C++ with use of boost::variant. Program's code is presented below.
#include <string>
#include <iostream>
#include <boost/variant.hpp>
int main (int argc, char** argv)
{
boost::variant<int, std::wstring> v;
v = 3;
std::cout << v << std::endl;
return 0;
}
But when I try to compile this with command
g++ main.cpp -o main -lboost_system
i get
/usr/include/boost/variant/detail/variant_io.hpp:64: error: no match for ‘operator<<’ in ‘((const boost::detail::variant::printer<std::basic_ostream<char, std::char_traits<char> > >*)this)->boost::detail::variant::printer<std::basic_ostream<char, std::char_traits<char> > >::out_ << operand’
followed by a bunch of candidate functions.
What I'm missing? The funny thing is When I use std::string
instead of std::wstring
everything works great.
Thanks in advance.
The problem is that wstring
cannot be <<
in cout
. Try using wcout
instead. This is not a problem with the variant.
Use wcout
, not cout
. Because you're using wstring
, not string
.
std::wcout << v << std::endl;
//^^^^ note
Demo : http://ideone.com/ynf15
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With