C++ Tutorial/set multiset/set begin end


Deprecated: Constant E_STRICT is deprecated in /var/www/cppe.ru/www/includes/exception/MWExceptionHandler.php on line 179

Deprecated: Creation of dynamic property PPDStack::$accum is deprecated in /var/www/cppe.ru/www/includes/parser/Preprocessor_DOM.php on line 803

Deprecated: Constant E_STRICT is deprecated in /var/www/cppe.ru/www/includes/exception/MWExceptionHandler.php on line 179

Deprecated: Constant E_STRICT is deprecated in /var/www/cppe.ru/www/vendor/mediawiki/at-ease/src/Functions.php on line 48
Материал из C\C++ эксперт
Перейти к: навигация, поиск

Use std::copy to print all elements in a set

#include <iostream>
using std::cout;
using std::endl;
#include <set>
#include <algorithm>
#include <iterator> // ostream_iterator
int main()
{
   double a[ 5 ] = { 2.1, 4.2, 9.5, 2.1, 3.7 };
   std::set< double, std::less< double > > doubleSet( a, a + 5 );;
   std::ostream_iterator< double > output( cout, " " );
   cout << "doubleSet contains: ";
   std::copy( doubleSet.begin(), doubleSet.end(), output );
   cout << endl;
   return 0;
}
doubleSet contains: 2.1 3.7 4.2 9.5