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

Added the pad_int_with_zeros() function.

parent 7ec5fc07
......@@ -4,9 +4,11 @@
#define DLIB_STRINg_
#include "string_abstract.h"
#include <sstream>
#include "../algs.h"
#include <string>
#include <iostream>
#include <iomanip>
#include "../error.h"
#include "../assert.h"
#include "../uintn.h"
......@@ -257,6 +259,18 @@ namespace dlib
}
#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
......
......@@ -113,6 +113,19 @@ namespace dlib
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 <
......
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