File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 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
59namespace 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
Original file line number Diff line number Diff line change 1- #include < iostream>
21#include " binary.h"
32namespace 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
Original file line number Diff line number Diff line change @@ -4,11 +4,12 @@ using namespace std;
44
55int 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
You can’t perform that action at this time.
0 commit comments