Commit 636144d5 authored by Davis King's avatar Davis King

Added the pad_int_with_zeros() function.

parent 7ec5fc07
...@@ -4,9 +4,11 @@ ...@@ -4,9 +4,11 @@
#define DLIB_STRINg_ #define DLIB_STRINg_
#include "string_abstract.h" #include "string_abstract.h"
#include <sstream>
#include "../algs.h" #include "../algs.h"
#include <string> #include <string>
#include <iostream> #include <iostream>
#include <iomanip>
#include "../error.h" #include "../error.h"
#include "../assert.h" #include "../assert.h"
#include "../uintn.h" #include "../uintn.h"
...@@ -257,6 +259,18 @@ namespace dlib ...@@ -257,6 +259,18 @@ namespace dlib
} }
#endif #endif
// ----------------------------------------------------------------------------------------
inline std::string pad_int_with_zeros (
int i,
unsigned long width = 6
)
{
std::ostringstream sout;
sout << std::setw(width) << std::setfill('0') << i;
return sout.str();
}
// ---------------------------------------------------------------------------------------- // ----------------------------------------------------------------------------------------
class string_cast_error : public error class string_cast_error : public error
......
...@@ -113,6 +113,19 @@ namespace dlib ...@@ -113,6 +113,19 @@ namespace dlib
item into a std::string. item into a std::string.
!*/ !*/
// ----------------------------------------------------------------------------------------
std::string pad_int_with_zeros (
int i,
unsigned long width = 6
);
/*!
ensures
- converts i into a string of at least width characters in length. If
necessary, the string will be padded with leading zeros to get
to width characters.
!*/
// ---------------------------------------------------------------------------------------- // ----------------------------------------------------------------------------------------
template < template <
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment