Welcome to collectivesolver - Programming & Software Q&A. A website you can trust. I check, compile and run every program. Contact me at: aviboots(AT)netvision.net.il
Hostgator 1 Penny

BlueHost Web Hosting

Ecommerce Software - Best Ecommerce Platform Made for You - Free Trial

Ecommerce Software - Best Ecommerce Platform Made for You - Free Trial

getflywheel wordpress hosting


Distribute your Resume to 500+ Job Boards & Recruiters


6,857 questions

9,761 answers

573 users

How to shrink vector capacity to fit in C++

1 Answer

0 votes
#include <iostream>  
#include <string>  
#include <vector>  

int main()
{
	std::vector<std::string> vec_str;

	vec_str.reserve(5);

	vec_str.push_back("c++");
	vec_str.push_back("c");

	std::cout << "size() =     " << vec_str.size() << std::endl;
	std::cout << "capacity() = " << vec_str.capacity() << std::endl;

	vec_str.shrink_to_fit();

	std::cout << "size() =     " << vec_str.size() << std::endl;
	std::cout << "capacity() = " << vec_str.capacity() << std::endl;

	return 0;
}

/*
run:

size() =     2
capacity() = 5
size() =     2
capacity() = 2

*/

 




answered Jan 4 by avibootz
...