Retrieve vector content for a special type

Hello, given I am saving content to a vector std::vector<IP> list, how can I retrieve all the content in the vector?

I am trying this:
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
52
53
54
55
56
void IPManager::createUn(const std::string& file)
{

    std::ofstream f;
    f.open(file);
    for (IP element : list) 
    {
        std::cout << element; //****** Getting an error here
            
    }
    f.close();
   
}




//(..)
 IPManager::IPManager()
{
}

//This method will read IP, MAC address, interface etc from a .txt file.
//Then save the content to a vector defined as std::vector<IP> list
void IPManager::load(const std::string &file)
{
    std::ifstream f;
    f.open(file);
    std::string output;

    f >> output;
    std::cout << output;

    std::string tmp_intf;
    std::string tmp_ip;
    int tmp_mask;
    std::string tmp_mac;
    int tmp_rec;
    int tmp_sent;

    std::stringstream readf(output);
    readf >> tmp_intf >> tmp_ip >> tmp_mask >> tmp_mac >> tmp_rec >> tmp_sent;

    IP myread;
    myread.setIP(tmp_ip);
    myread.setInterfaceName(tmp_intf);
    myread.setMask(tmp_mask);
    myread.setMACAddress(tmp_mac);
    myread.setTrafficRec(tmp_rec);
    myread.setTrafficSent(tmp_sent);
    //Add the IP address, interface, mac information etc to a vector
    list.push_back(myread); //<===== Save to vector here
    f.close();
 
}
I don't know what an "IP" is. Is your class? Is it someone else's class? Evidently there's no operator<<() overload, so if you want line 8 to work you'll have to define one, I guess.
Topic archived. No new replies allowed.