Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Prodentim Probiotics Specially Designed For The Health Of Your Teeth And Gums

Instant Grammar Checker - Correct all grammar errors and enhance your writing

Teach Your Child To Read

Powerful WordPress hosting for WordPress professionals

Disclosure: My content contains affiliate links.

31,104 questions

40,777 answers

573 users

How to get vector size and capacity in C++

2 Answers

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

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

	vec_str.reserve(4);

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

	return 0;
}

/*
run:

size() =     0
capacity() = 4

*/

 





answered Jan 3, 2018 by avibootz
0 votes
#include <iostream>  
#include <string>  
#include <vector>  

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

	vec_str.reserve(4);

	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;

	return 0;
}

/*
run:

size() =     2
capacity() = 4

*/

 





answered Jan 3, 2018 by avibootz

Related questions

2 answers 71 views
1 answer 26 views
1 answer 67 views
1 answer 105 views
...