forked from mrchuanxu/RegularNotes
-
Notifications
You must be signed in to change notification settings - Fork 0
/
stlib.cpp
77 lines (73 loc) · 2.2 KB
/
stlib.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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#include <tuple>
#include <iostream>
#include <string>
#include <vector>
#include <bitset>
#include <regex>
#include <random>
#include <iomanip>
using namespace std;
/***
* 可以利用tuple返回多个值
* bitset位运算变得容易
* 使用正则表达式regex
* random 定义为static 引擎才能生成不同的序列 引擎要在循环外定义,不然保持不了状态
* 使用io库
* seek与tell 读取文件任意位置
*
* ***/
int main(){
tuple<int,double,float,string> t(1,1.23,1.44,"fuck you");
cout << get<2>(t)*0.8 << endl;
typedef decltype(t) trans;
size_t sz = tuple_size<trans>::value;
cout << sz << endl;
tuple<string,vector<string>,pair<string,int>> tsvp("fuck off",{"no way"},{"yes",1});
cout << get<1>(tsvp)[0] << endl;
bitset<32> bitvec(1U);
bitset<13> bitvec1(0xbeef);
cout << bitvec1<<endl;
bitset<16> bitvec2(9);
cout << bitvec2 << endl;
bitvec2.flip();
cout << bitvec2 << endl;
bitvec2.set(bitvec2.size()-1,0);
cout << bitvec2 << endl;
bitset<30> quizB;
quizB.set(27);
cout << quizB << endl;
string pattern("[^c]ei");
pattern = "[[:alpha:]]*"+pattern+"[[:alpha:]]*";
regex r(pattern,regex::icase);
// smatch results;
string test_str = "receipt freind theif receive";
for(sregex_iterator it(test_str.begin(),test_str.end(),r),end_it;it!=end_it;++it){
cout << it->str() << endl;
}
uniform_int_distribution<unsigned> u(0,9);
default_random_engine e;
for(size_t i =0; i<10;++i){
cout << u(e) << endl;
}
uniform_real_distribution<double> u1(0,1);
default_random_engine ran;
for(size_t i =0; i<10;++i){
cout << u1(ran) << endl;
}
char resp;
// bernoulli_distribution be(0.55);
// do{
// bool fisrt = be(e);
// cout << (fisrt?"We go first":"you go first") <<endl;
// }while(cin >> resp && resp[0] == 'y');
bool bool_val = true;
cout << boolalpha << bool_val << noboolalpha;
cout << showbase;
cout << oct << 20 << endl;
cout << hex << 20 << noshowbase<<endl;
//cout << dec <<20<<noshowbase;
cout<<cout.precision(12)<<sqrt(2.0)<<endl;
while(cin.get(resp))
cout.put(resp);
return 0;
}