Total members 11892 |It is currently Fri Oct 18, 2024 7:38 am Login / Join Codemiles

Java

C/C++

PHP

C#

HTML

CSS

ASP

Javascript

JQuery

AJAX

XSD

Python

Matlab

R Scripts

Weka





Get number of elements in a Vector using C++
cpp code
#include <iostream>
using std::cout;
using std::endl;

#include <algorithm>
#include <numeric>
#include <vector>
#include <iterator>

int main()
{
std::ostream_iterator< int > output( cout, " " );

int a2[ 10 ] = { 100, 2, 8, 1, 50, 3, 8, 8, 9, 10 };
std::vector< int > v2( a2, a2 + 10 ); // copy of a2
cout << "Vector v2 contains: ";
std::copy( v2.begin(), v2.end(), output );

// count number of elements in v2 with value 8
int result = std::count( v2.begin(), v2.end(), 8 );
cout << "\nNumber of elements matching 8: " << result;

cout << endl;
return 0;
}

/*
Vector v2 contains: 100 2 8 1 50 3 8 8 9 10
Number of elements matching 8: 3

*/




_________________
Please recommend my post if you found it helpful


Author:
Beginner
User avatar Posts: 95
Have thanks: 2 time
Post new topic Reply to topic  [ 1 post ] 

  Related Posts  to : count elements in a vector
 Vector class     -  
 vector front     -  
 C++ Vector capacity     -  
 SQL COUNT Command     -  
 Iterator on Vector     -  
 Data Structures: Vector     -  
 String char count     -  
 Unique Row Count Across Columns     -  
 Write Vector list to File     -  
 Return words count in a string     -  



Topic Tags

C++ Data Structures






Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
All copyrights reserved to codemiles.com 2007-2011
mileX v1.0 designed by codemiles team
Codemiles.com is a participant in the Amazon Services LLC Associates Program, an affiliate advertising program designed to provide a means for sites to earn advertising fees by advertising and linking to Amazon.com