Answer the question
In order to leave comments, you need to log in
The size of the class in the container (for example std::vector)
It would be desirable to learn the size (sizeof) of a class which is stored in the container (for example std::vector).
If the container is not empty, then this is elementary. I see a solution like this:
std::vector<int> v;
if(v.size > 0){
std::cout << sizeof(v[0]) << std::endl;
}else{
//эта часть смущает
v.push_back(0);
std::cout << sizeof(v[0]) << std::endl;
v.clear();
}
std::vector<int> v;
v.push_back(0);
std::cout << sizeof(v[0]) << std::endl;
v.pop_back();
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question