-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
20 changed files
with
312 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,4 +2,9 @@ | |
|
||
这里是我的个人笔记仓库 | ||
|
||
主要用来存储自己学习CS的一些笔记 | ||
主要用来存储自己学习CS的一些笔记 | ||
|
||
使用mkdocs搭建,主题为material for mkdocs | ||
|
||
Pages: zzicarus.github.io | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
## IO类 | ||
|
||
- IO对象无赋值无拷贝 | ||
![alt text](images/custom-image.png) | ||
|
||
### 条件状态 | ||
|
||
![alt text](images/custom-image-2.png) | ||
|
||
#### 流的状态 | ||
|
||
`iostate`类型 | ||
![alt text](images/custom-image-3.png) | ||
|
||
- 可以利用`good() fail()`判断整体流的状态 | ||
|
||
### 管理缓冲 | ||
|
||
!!! note "刷新缓冲的原因" | ||
![alt text](images/custom-image-4.png) | ||
<span class="box box-yellow">操纵符</span> | ||
|
||
![alt text](images/custom-image-5.png) | ||
```Cpp | ||
cout << unitbuf; // 所有cout操作之后都刷新buffer | ||
cout << nounitbuf; | ||
``` | ||
|
||
**流的关联操作** | ||
|
||
```c++ | ||
cin.tie(&cout); | ||
// old_tie指向的是cin的关联流;转化后,cin不再关联 | ||
ostream *old_tie = cin.tie(nullptr); | ||
cin.tie(&cerr); | ||
cin.tie(old_tie); | ||
``` | ||
|
||
## File | ||
|
||
![alt text](images/custom-image-6.png) | ||
|
||
```cpp | ||
ifstream in; | ||
ofstream out; | ||
string filename("CppLearning"); | ||
in.open(filename + ".md"); | ||
if (in) | ||
{ //... | ||
} | ||
in.close(); | ||
``` | ||
### 文件模式 | ||
![alt text](images/custom-image-7.png) | ||
"../Stadard_Library/关联容器.md" | ||
!!! note "注意" | ||
以`out`方式打开文件,默认会覆盖 | ||
```cpp | ||
ofstream out("filename",mode); | ||
ofstream out("filename",ofstream::app | ofstream::out); | ||
``` | ||
|
||
## String | ||
|
||
![alt text](images/custom-image-8.png) | ||
|
||
!!! example "Example" | ||
使用`istringstream`读取,ostringstream输入 | ||
使用`ostringstream`可以在适当的时机输出所有值 | ||
```c++ hl_lines="7 10 12" title="istringstream" | ||
string str, line; | ||
vector<PersonInfo> People; | ||
while (getline(cin, line)) | ||
{ | ||
PersonInfo Person; | ||
string name, numbers; | ||
istringstream iStr(line); | ||
iStr >> name; | ||
Person.name = name; | ||
while (iStr >> numbers) | ||
{ | ||
Person.Phones.push_back(numbers); | ||
} | ||
People.push_back(Person); | ||
} | ||
for (auto person : People) | ||
{ | ||
cout << "name:" << person.name << endl; | ||
cout << "phones:" << endl; | ||
for (auto phone : person.Phones) | ||
cout << phone << endl; | ||
} | ||
``` | ||
|
||
|
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,132 @@ | ||
!!! abstract "Abstract" | ||
一个容器是一些特定类型对象的集合。 | ||
所有容器类都共享公共的接口,不容的容器按照不同的方式进行拓展。<br> | ||
**一般情况下,范围 range(a,b) 指的是[a,b)** | ||
|
||
- 类型 | ||
![alt text](images/custom-image-9.png) | ||
|
||
## 基本操作 | ||
|
||
![alt text](images/custom-image-10.png) | ||
|
||
### 定义 初始化 | ||
|
||
```Cpp | ||
// 返回反向容器 | ||
reverse_iterator | ||
const_reverse_iterator | ||
c.rbegin() c.rend() | ||
``` | ||
|
||
### 赋值与swap | ||
|
||
```c++ | ||
c1 = c2; | ||
c = {a,b,c}; | ||
swap(c1,c2); | ||
c1.swap(c2); | ||
seq.assign(b,e); // b,e指向的不能是seq中的 | ||
seq.assign(initialList); | ||
seq.assign(n,val); | ||
``` | ||
> 除了数组之外,Swap操作不对数据进行拷贝、删除、插入,可以在常数时间内完成 | ||
## 顺序容器 | ||
### 操作 | ||
```c++ | ||
// 添加元素 | ||
c.push_back(t); | ||
c.push_front(t); | ||
c.emplace_front(args); | ||
c.emplace_back(args); | ||
//返回第一个新加入元素的迭代器 | ||
c.insert(position,n,val); // position 为 迭代器 | ||
c.insert(position,begin,end); | ||
c.insert(position,initialList); | ||
// 位置 | ||
c.at(n); | ||
// 删除 | ||
c.pop_back(); | ||
c.pop_front(); | ||
c.erase(position); | ||
c.erase(b,e); | ||
// 改变大小 | ||
c.resize(n,optional::val); | ||
// 容量大小 | ||
c.capacity(); | ||
c.size(); | ||
c.shrink_to_fit(); | ||
c.reserve(n); | ||
``` | ||
|
||
!!! note "添加元素" | ||
- emplace与push、insert的不同在于,emplace是通过元素的构造函数直接构造一个新的元素;而另外两者是拷贝的方式 | ||
|
||
#### forward_list | ||
|
||
```c++ | ||
flits.before_begin(); | ||
flits.insert_after(...); | ||
emplace_after(iter_position,args); | ||
flits.erase_after(position); | ||
flits.erase_after(b,e); | ||
``` | ||
#### String | ||
![alt text](images/custom-image-11.png) | ||
```c++ | ||
// 构造函数 | ||
string s1(cp,n); // cp[n]之前 | ||
string s2(str,pos); // str[pos]之后 | ||
string s3(str,pos,len); | ||
// | ||
s.substr(pos,n); // position n个 | ||
// 插入 char / string | ||
s.insert(nth,""); | ||
s.append(""); | ||
s.replace(); | ||
``` | ||
|
||
!!! note "搜索操作" | ||
注意,**find()函数的返回值是 `unsigned` 类型**,string::size_type npos = -1; | ||
```c++ | ||
// 全匹配 | ||
s.find(); | ||
s.rfind(); // 最后一次出现 | ||
// 部分匹配 | ||
s.find_first_of(); | ||
s.find_first_not_of(); | ||
s.find_last_of(); | ||
s.find_last_not_of(); | ||
// example | ||
cout << a.find(); // Not Found: 18446744073709551615 | ||
string str = "he is not here"; | ||
cout << str.find("he") << endl; | ||
cout << str.substr(str.find("he"), sizeof("he")); | ||
// example 选择匹配 | ||
string str = "11h23e55 i4456s88 n77o97t here!"; | ||
string numbers("0123456789"); | ||
string result(""); | ||
string::size_type pos = 0; | ||
while ((pos = str.find_first_not_of(numbers, pos)) != string::npos) | ||
{ | ||
result.push_back(str[pos]); | ||
pos++; | ||
} | ||
cout << result; | ||
``` | ||
|
||
### 适配器 | adaptor | ||
|
||
> 适配器可以将一个类的接口转化为另外一个类的接口。 | ||
> 通过包装一个底层的类,对其接口进行二次处理,呈现出一种新的形式 | ||
> 一般情况下,`stack` `queue`基于`dequeue`实现,`priority_queue`基于vector实现(**也可以通过重载改变**,但需要满足适配器的特性) | ||
> 如 `stack<string, vector<string>> str_stk;` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,32 +1,22 @@ | ||
#include <iostream> | ||
|
||
#include <array> | ||
#include <vector> | ||
#include <fstream> | ||
#include <list> | ||
#include <forward_list> | ||
#include <sstream> | ||
#include <string> | ||
#include <stack> | ||
using namespace std; | ||
|
||
std::string to_camel_case(std::string text) | ||
struct PersonInfo | ||
{ | ||
int flag_count = 0; | ||
string result; | ||
for (auto single : text) | ||
{ | ||
if (single == '_' || single == '-') | ||
flag_count = 1; | ||
if (flag_count == 1) | ||
{ | ||
if (isalpha(single)) | ||
{ | ||
result.push_back(toupper(single)); | ||
flag_count = 0; | ||
} | ||
} | ||
else | ||
{ | ||
result.push_back(single); | ||
} | ||
} | ||
return result; | ||
} | ||
string name; | ||
vector<string> Phones; | ||
}; | ||
|
||
int main() | ||
{ | ||
cout << to_camel_case("The_Formal_language"); | ||
int aaSSD_dawj = 5; | ||
string asd; | ||
} |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters