Skip to content

Instantly share code, notes, and snippets.

@dgodfrey206
dgodfrey206 / Locale
Created November 2, 2013 22:07
My implementation of a manipulator that saves a locale name to the stream. Still needs work.
#include <iostream>
#include <string>
#include <locale>
#include <vector>
static int index()
{
static int idx = std::ios_base::xalloc();
return idx;
}
@dgodfrey206
dgodfrey206 / gist:7387773
Created November 9, 2013 17:36
A function for find if a string is a substring of another string
#include <iostream>
#include <string>
bool is_substring_of(const std::string& substr, const std::string& str)
{
auto it = substr.begin();
for (auto const& c : str)
{
if (c == *it)
@dgodfrey206
dgodfrey206 / gist:7434236
Created November 12, 2013 16:43
How to append a string to an int using the parsing and formatting facets from the IOStreams library.
#include <iostream>
#include <locale>
#include <string>
template <class Facet>
struct erasable_facet : Facet
{
erasable_facet() : Facet(0) { }
~erasable_facet() { }
};
@dgodfrey206
dgodfrey206 / gist:7434945
Created November 12, 2013 17:24
Converting a string to an integer (could use more work)
#include <iostream>
#include <locale>
template <class Facet>
struct erasable_facet : Facet
{
erasable_facet() : Facet(0) { }
~erasable_facet() { }
};
@dgodfrey206
dgodfrey206 / gist:7442247
Created November 13, 2013 01:54
How to convert a string of doubles into a vector
#include <iostream>
#include <vector>
#include <string>
#include <sstream>
template <class Facet>
struct erasable_facet : Facet
{
erasable_facet() : Facet(0) { }
~erasable_facet() { }
@dgodfrey206
dgodfrey206 / gist:7442430
Created November 13, 2013 02:10
An almost complete implementation of an iterator designed for C-style arrays.
#include <iostream>
#include <vector>
template <class T, class CharT = char, class Traits = std::char_traits<char>>
class array_iterator : public std::iterator<std::output_iterator_tag,
void, void, void, void>
{
public:
array_iterator(T* list)
: array(list) { }
@dgodfrey206
dgodfrey206 / gist:7476217
Last active December 28, 2015 09:09
Getting key value pairs from a file.
#include <iostream>
#include <limits>
#include <string>
#include <fstream>
namespace utility
{
class stream_ok
{
public:
@dgodfrey206
dgodfrey206 / gist:7492301
Created November 15, 2013 21:54
A function that finds the largest lexographically-increasing substring in a string.
#include <iostream>
#include <vector>
#include <utility>
#include <algorithm>
#include <string>
std::string longest_alpha_substr(const std::string& str)
{
char last = str[0];
int size = 1;
@dgodfrey206
dgodfrey206 / gist:7553400
Last active December 28, 2015 19:49
My try at the address_put facet from the book Standard C++ IOStreams and Locales
#include <iostream>
#include <string>
#include <locale>
#include <typeinfo>
#include <map>
template<class charT>
class address
{
template<class CharT>
@dgodfrey206
dgodfrey206 / gist:7574773
Created November 21, 2013 01:52
Extracting the first and last name from a stream into variables
#include <iostream>
#include <string>
#include <locale>
#include <sstream>
template<
class charT,
class iter_type,
class string_iterator_type
>