Skip to content

Instantly share code, notes, and snippets.

View steveobbayi's full-sized avatar

Steve Obbayi steveobbayi

View GitHub Profile
...
vector<int> v = {2,5,3,6,4,8,5,9,6,1,7,3,12,14,25};
int a = min_element(v.begin(), v.end());
// The value of "a" above is 1
...
vector<int> v = {2,5,3,6,4,8,5,9,6,1,7,3,12,14,25};
int a = max_element(v.begin(), v.end());
// The value of "a" above is 25
...
vector<int> v = {2,5,3,6,4,8,5,9,6,1,7,3,12,14,25};
int a = count(v.begin(), v.end(), 3);
// The value of "a" is 2
//Below we use a lambda and count_if to see how many elements
//are greater than 10
int b = count_if(v.begin(), v.end(),[](int x){return x > 10;});
// The value of "b" above is 3
// Basic usage
// Integer
fmt::format("The year is {}", 2016);
// Print String
fmt::print("This is a {}\n", "boring string");
// Making use of variadic templates
fmt::print("I'm eating {1} and {0}.", "chips", "fish"); //outputs I'm eating fish and chips
// Memory writer example from offical site
fmt::MemoryWriter w;
vector v = {3,6,1,8,2}; //the container
// The Iterators
vector::iterator it1 = v.begin();
vector::iterator it2 = v.end();
// The Algorithm
sort(it1, it2);
// return a the list {1,2,3,6,8};
using namespace std;
vector v; //the container
//populate the vector
v.push_back(3);
v.push_back(6);
v.push_back(1);
v.push_back(8);
v.push_back(2);
int main()
{
char c[10];
c[10] = 0;
return 0;
}
// using offsets
for (int i; i < vec.size(); i++){
cout << vec[i] << endl;
}
// same results using iterator
for (vector::iterator i = vec.begin(); i != vec.end(); ++i){
cout << *i << endl;
// vec: {3, 4, 6, 8}
cout vec.at(3); // ret 8: throws range_error exception if out of scope
cout vec[3]; // ret 8: no range check
#include <vector>
#include <list>
#include <deque>
#include <array>