Library <vector> task

Write your question here.






using vector Library i need to put a miliard numbers of int and string into a container and cout the 26's member and 968677727 member,can you help me with this task?
miliard numbers of int
It is almost 4 Gb of memory if int is 4-byte.
std::string will take at least 16 Gb.

Are you sure you should do this?
hmmm maybe i translated the task wrong i will try to explain as good as i can :



Using library vector. into the Container put a miliard Objects,that are from random int and random string type and cout to the screen the object 26 and object 96867772

i hope i made a better explanation,this i my exam task and i made the first task this is the seconde and i just dont get it i havent been learnin this yet.
Last edited on
Unless you have monster machine with 16Gb RAM onboard trying to allocate 1 000 000 000 values with standard library vector is likely to give you an bad_alloc exception. There is code for vector of int, but it probably will crash on you because of insufficient RAM:
1
2
3
4
5
6
7
8
9
10
11
#include <iostream>
#include <algorithm>
#include <vector>
#include <random>

int main()
{
    std::vector<int> x(1000000000uLL);
    std::generate(x.begin(), x.end(), std::rand);
    std::cout << x[26] << ' ' << x[96867772uLL];
}

Last edited on
i know about the problem of ram i asked my teacher if its trully is the task he said yes and said you have to use it as object,said you have to use class and public and show and something else to make it happen.
Even if you use object which will hold integer and string, you std::vector of pointer to said objects is still will be almost 4Gb on 32x machine. And I even not started to count actual memory consumption of objects.

EDIT: Even the vector of ints if about 4Gb, what can you think about vector of ints and strings?
Last edited on
the teacher said its posible,but anyway thx for replays,i wont try to do this task and movie onto the next task, ty mate.
It's likely you don't need to run the actual program, so what you could do is design it for 1000 of those objects, make sure it works, then modify it for 100,000,000 objects without running it (but compiling)
Topic archived. No new replies allowed.