Skip to content

Commit ad540a6

Browse files
committed
updata
1 parent d6aa250 commit ad540a6

4 files changed

Lines changed: 32 additions & 2 deletions

File tree

binary/include/binary.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,16 @@
11
#ifndef BINARY_H
22
#define BINARY_H
33
#include <iostream>
4+
#include <string>
5+
#include <sstream>
6+
#include <vector>
7+
using namespace std;
48

59
namespace myLib
610
{
711
int count_binary(int n);
812
std::string toHex(int num);
13+
std::string int2String(int n);
14+
vector<string> int2VString(int n);
915
}
1016
#endif

binary/scr/binary.cpp

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
#include<iostream>
21
#include"binary.h"
32
namespace myLib
43
{
@@ -34,5 +33,29 @@ namespace myLib
3433
return ans;
3534
}
3635

36+
/**************************************************
37+
* * @file binary.cpp
38+
* * @author EncodedStar
39+
* * @date 2019.7.5
40+
* * @function int转化string and vector<string>
41+
***************************************************/
42+
std::string int2String(int n) {
43+
std::stringstream tmpss;
44+
std::string tmps;
45+
tmpss.clear();
46+
tmpss << n;
47+
tmpss >> tmps;
48+
tmpss.str("");
49+
return tmps;
50+
}
51+
vector<string> int2VString(int n) {
52+
vector<string> tmpv;
53+
for(int i = 1; i <= n; i++)
54+
{
55+
tmpv.push_back(int2String(i));
56+
}
57+
return tmpv;
58+
}
59+
3760
}
3861

binary/scr/binary.o

30.7 KB
Binary file not shown.

main.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,12 @@ using namespace std;
44

55
int main()
66
{
7-
cout << "hello" << endl;
87
cout << myLib::count_binary(1) << endl;
98
cout << myLib::count_binary(9) << endl;
109
cout << myLib::toHex(26) << endl;
1110
cout << myLib::toHex(-1) << endl;
11+
for(auto a:myLib::int2VString(15))
12+
cout << a << endl;
1213
}
1314

1415

0 commit comments

Comments
 (0)