how to print the content of vector of variant of vector

Dear Pls look at my code,
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
When I try to print the content of vector of structure of variant of vector the following big unbelievable error even it is very simple.

#include<iostream>
#include<boost/variant.hpp>
#include<vector>
#include<string>

using namespace std;


typedef std::string net_id;
typedef std::vector<net_id> netwk_id;

struct network
{

boost::variant<netwk_id> _netwk_inc;
};

typedef vector<network> network_list;


int main()
{

netwk_id net1;
net1.push_back("202");

network net2;
net2._netwk_inc = net1;


network_list net3;
net3.push_back(net2);

for(int i =0; i< net3.size(); ++i)
{
cout << net3[0]._netwk_inc ;
}

}

Error;

In file included from /usr/include/boost/variant/variant.hpp:1892:0,
                 from /usr/include/boost/variant.hpp:17,
                 from bin_query.cpp:2:
/usr/include/boost/variant/detail/variant_io.hpp: In member function ‘void boost::detail::variant::printer<OStream>::operator()(const T&) const [with T = std::vector<std::basic_string<char> >, OStream = std::basic_ostream<char>]’:
/usr/include/boost/variant/variant.hpp:858:32:   instantiated from ‘boost::detail::variant::invoke_visitor<Visitor>::result_type boost::detail::variant::invoke_visitor<Visitor>::internal_visit(T&, int) [w

Pls any body can suggest how to get out of this problem
I don't see a problem here to be solved. I see an unindeted code messed up with text and I don't know where to look to tell you where the problem comes from. I'm so sorry.

Sort out your code, use indents, and write a comment beside the place where the error occures, so that people can help you.
Last edited on
Ok Please see the bellow code

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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50

When I try to print the content of vector of structure of variant of vector the following big unbelievable error even it is very simple.

#include<iostream>
#include<boost/variant.hpp>
#include<vector>
#include<string>

using namespace std;


typedef std::string net_id;
typedef std::vector<net_id> netwk_id;

// Structure to hold the vector of netid's and some more information that I am not included here bcz it is //similar one.
struct network
{
boost::variant<netwk_id> _netwk_inc;
};

// Here I am making vector containing the above structure  // this vector only available at other side //meaning I am sending this vector through socket programming to some other server so that there I //have to decode or extract this information.
  
typedef vector<network> network_list;


int main()
{
 
// here I am assigning my netid to vector 
netwk_id net1;
net1.push_back("202");

// here I am assigning vector to structure variable of type boost variant

network net2;
net2._netwk_inc = net1;

// finally I am pushing structure into vector 

network_list net3;
net3.push_back(net2);

// Now see here i am trying to print the content of vector what ever may be I assigned earlier . but here //only it is showing error
// I don't know exactly how to extract the content 
for(int i =0; i< net3.size(); ++i)
{
cout << net3[0]._netwk_inc ;
}

}
Please indent your code.
You are trying to print a vector.
The compiler does not know how to do that. Teach it.
pls let me know how to do that .
Really I am confusing over boost::variant of vector .
Again, it's irrelevant that you are using boost::variant

Define somewhere
1
2
3
std::ostream& operator<<(std::ostream &out, const std::vector<net_id> &v){
//...
}
Topic archived. No new replies allowed.