how to get last element of set in c++
set s = {1,2,3}
auto it = s.end();
it--;
cout<<*it<<"\n"; // This refers to last element of a set
PRINT IN C ++
#include
std::cout << someString << "\n";
print set c++
// INTEGER SET EXAMPLE
// CPP program to illustrate
// Implementation of begin() function
#include
#include
using namespace std;
int main()
{
// declaration of set container
set myset{ 1, 2, 3, 4, 5 };
// using begin() to print set
for (auto it = myset.begin(); it !=myset.end(); ++it)
cout << ' ' << *it;
return 0;
}
|