-
Notifications
You must be signed in to change notification settings - Fork 0
/
int2str.cpp
41 lines (38 loc) · 898 Bytes
/
int2str.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#include <iostream>
#include <sstream>
#include <string>
#include "int2str.h"
void int2str( const unsigned long i,
const size_t width, // how many digits to output
std::string & str) {
if (width >= 20) {
std::cerr << "A width of " << width << " is too large!" << std::endl;
}
std::stringstream tmp;
tmp << i;
str = tmp.str();
while (str.size() < width) {
str = "0" + str;
}
}
std::string int2str(const unsigned long i,
const size_t width){ // how many digits to output
if (width >= 20) {
std::cerr << "A width of " << width << " is too large!" << std::endl;
}
std::stringstream tmp;
std::string str;
tmp << i;
str = tmp.str();
while (str.size() < width) {
str = "0" + str;
}
return str;
}
std::string int2str(const unsigned long i){
std::stringstream tmp;
std::string str;
tmp << i;
str = tmp.str();
return str;
}