#include <string> std::string tabToSpace(int tabSize, const std::string& s) { std::string result; int spacingSize = tabSize; for(std::string::const_iterator i = s.begin(); i != s.end(); ++i) { if(*i == '\t') { result += std::string(spacingSize, ' '); spacingSize = tabSize; } else { result += *i; --spacingSize; if(spacingSize == 0) { spacingSize = tabSize; } } } return result; }