Sunday, March 24, 2013

C++ string tokenizer

The advanced tokenizer:

void Tokenize(const string& str,
                      vector& tokens,
                      const string& delimiters = " ")
{
    // Skip delimiters at beginning.
    string::size_type lastPos = str.find_first_not_of(delimiters, 0);
    // Find first "non-delimiter".
    string::size_type pos     = str.find_first_of(delimiters, lastPos);

    while (string::npos != pos || string::npos != lastPos)
    {
        // Found a token, add it to the vector.
        tokens.push_back(str.substr(lastPos, pos - lastPos));
        // Skip delimiters.  Note the "not_of"
        lastPos = str.find_first_not_of(delimiters, pos);
        // Find next "non-delimiter"
        pos = str.find_first_of(delimiters, lastPos);
    }
}

Source: http://oopweb.com/CPP/Documents/CPPHOWTO/Volume/C++Programming-HOWTO-7.html

C++ string to double and vice versa

The C++ 11 way is to use std::stod and std::to_string. Both work in Visual Studio 11.


The STL offers the desired functionality:
std::string  s  = "0.6"
std::wstring ws = "0.7"
double d  = std::stod(s);
double dw = std::stod(ws);


http://stackoverflow.com/questions/1012571/stdstring-to-float-or-double

Monday, March 4, 2013

Latex packages: 9 essential

http://www.howtotex.com/packages/9-essential-latex-packages-everyone-should-use/