This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
... | |
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
... | |
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
... | |
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
int main() | |
{ | |
char c[10]; | |
c[10] = 0; | |
return 0; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <vector> | |
#include <list> | |
#include <deque> | |
#include <array> |