How to find max_size, size and capacity of a vector of strings in C++

1 Answer

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

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

	vec_str.reserve(4);

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

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

	return 0;
}

/*
run:

max_size() = 153391689
size() =     4
capacity() = 4

*/

 



answered Jan 3, 2018 by avibootz

Related questions

2 answers 264 views
2 answers 273 views
1 answer 164 views
1 answer 188 views
1 answer 245 views
1 answer 171 views
1 answer 228 views
...