Std::distance C++ Code Example


Example: std distance

// Calculates the number of elements between first and last.  #include <iterator>     									// std::distance #include <vector>     										// std::vector #include <algorithm>   							// Just if you use std::find  vector<int> arr = {2,5,3,8,1}; int size = std::distance(arr.begin(), arr.end()); 			// 5  auto it = std::find(arr.begin(), arr.end(), 8); int position = std::distance(arr.begin(), it); 				// 3

Comments

Popular posts from this blog

Converting A String To Int In Groovy

"Cannot Create Cache Directory /home//.composer/cache/repo/https---packagist.org/, Or Directory Is Not Writable. Proceeding Without Cache"

Android How Can I Convert A String To A Editable