答辯最大的教訓(xùn)
做東西的不如賣(mài)東西的
吃一塹長(zhǎng)一智
寫(xiě)在前面
根據(jù)上一篇的大作業(yè)內(nèi)容块差,把自己一星期多以來(lái)使用到的一些知識(shí)點(diǎn)、一些好的博客內(nèi)容粘貼過(guò)來(lái),做一下自己的總結(jié)弓乙。
主要是自己的C基礎(chǔ)也比較差,平常用到一些很簡(jiǎn)單的知識(shí)的時(shí)候也會(huì)忘剑梳,要現(xiàn)查唆貌,就很浪費(fèi)時(shí)間。
1.C/C++基礎(chǔ)
1.1C++中setw()函數(shù)的使用
在C++中垢乙,setw(int n)用來(lái)控制輸出間隔锨咙。
例如:
cout<<'s'<<setw(8)<<'a'<<endl;
則在屏幕顯示
s a
s與a之間有7個(gè)空格,setw()只對(duì)其后面緊跟的輸出產(chǎn)生作用追逮,如上例中酪刀,表示'a'共占8個(gè)位置,不足的用空格填充钮孵。若輸入的內(nèi)容超過(guò)setw()設(shè)置的長(zhǎng)度骂倘,則按實(shí)際長(zhǎng)度輸出。
setw()默認(rèn)填充的內(nèi)容為空格巴席,可以setfill()配合使用設(shè)置其他字符填充历涝。
如
cout<<setfill('*')<<setw(5)<<'a'<<endl;
則輸出:
****a //4個(gè)*和字符a共占5個(gè)位置。
1.2c++實(shí)現(xiàn)按行讀取文本文件
#include<fstream> //ifstream讀文件,ofstream寫(xiě)文件荧库,fstream讀寫(xiě)文件
int main(){
SetConsoleOutputCP(65001);
ifstream in("1.txt");
string line;
if(in) // 有該文件{
while (getline (in, line)) // line中不包括每行的換行符{
cout << line << endl;
}
}
else // 沒(méi)有該文件{
cout <<"no such file" << endl;
}
system("pause");
return 0;
}
1.3C++讀取文件fopen堰塌、freopen
fopen
FILE *fp1,*fp2; //定義文件指針類型
fp1=fopen("input.in","r"); //用fopen函數(shù)以只讀方式(r)打開(kāi)輸入文件input.in;
fp2=fopen("output.out","w");//用fopen函數(shù)以寫(xiě)入方式(w)打開(kāi)輸出文件output.out;
fscanf(fp1,"%d",&temp);//fscanf從文件中讀取數(shù)據(jù)分衫,fp1文件指針指定文件场刑;
fprintf(fp2,"%d",temp);//fprintf將數(shù)據(jù)輸出到文件,fp2文件指針指定文件蚪战;
fclose(fp1);//關(guān)閉文件指針牵现。
fclose(fp2);
freopen
FILE * freopen(const char *filename, const char *mode,FILE *stream);
filename:要打開(kāi)的文件名;
mode:文件打開(kāi)的模式邀桑,和fopen中的模式(r/w)相同瞎疼。
stream:文件指針,通常使用標(biāo)準(zhǔn)流文件(stdin/stdout/stderr)
freopen("Mk02.txt", "r", stdin);
cin >> *n >> *m;
1.4 C++map
C++ maps是一種關(guān)聯(lián)式容器概漱,包含“關(guān)鍵字/值”對(duì)
1.構(gòu)造函數(shù)
map<int, string> mapStudent;
2.插入元素
// 定義一個(gè)map對(duì)象
map<int, string> mapStudent;
// 第一種 用insert函數(shù)插入pair
mapStudent.insert(pair<int, string>(000, "student_zero"));
// 第二種 用insert函數(shù)插入value_type數(shù)據(jù)
mapStudent.insert(map<int, string>::value_type(001, "student_one"));
// 第三種 用"array"方式插入
mapStudent[123] = "student_first";
mapStudent[456] = "student_second";
3.查找元素
iter = mapStudent.find("123");
if(iter != mapStudent.end())
cout<<"Find, the value is"<<iter->second<<endl;
else
cout<<"Do not Find"<<endl;
4.刪除元素
//迭代器刪除
iter = mapStudent.find("123");
mapStudent.erase(iter);
//用關(guān)鍵字刪除
int n = mapStudent.erase("123"); //如果刪除了會(huì)返回1丑慎,否則返回0
//清空
5.常用函數(shù)
mapStudent.clear()
begin() 返回指向map頭部的迭代器
clear() 刪除所有元素
count() 返回指定元素出現(xiàn)的次數(shù)
empty() 如果map為空則返回true
end() 返回指向map末尾的迭代器
equal_range() 返回特殊條目的迭代器對(duì)
erase() 刪除一個(gè)元素
find() 查找一個(gè)元素
get_allocator() 返回map的配置器
insert() 插入元素
key_comp() 返回比較元素key的函數(shù)
lower_bound() 返回鍵值>=給定元素的第一個(gè)位置
max_size() 返回可以容納的最大元素個(gè)數(shù)
rbegin() 返回一個(gè)指向map尾部的逆向迭代器
rend() 返回一個(gè)指向map頭部的逆向迭代器
size() 返回map中元素的個(gè)數(shù)
swap() 交換兩個(gè)map
upper_bound() 返回鍵值>給定元素的第一個(gè)位置
value_comp() 返回比較元素value的函數(shù)
2.CUDA基礎(chǔ)
2.1對(duì)新接觸CUDA非常友好的教程
詳細(xì)介紹了CUDA的運(yùn)行原理和模型,尤其是block, grid, thread, warp, SM的講解瓤摧,比較清晰竿裂,示例代碼比較基礎(chǔ)易懂。
https://zhuanlan.zhihu.com/p/34587739