一步一步CPP
rockets311
Im a coder...
展开
-
智能指针之auto_ptr
什么是智能指针是包含重载运算符的类,其行为像常规指针,但智能指针能及时、妥善地销毁动态分配的数据,并实现了定义良好的对象生命周期管理策略。智能指针是如何实现的重载了运算符*和运算符->,让程序员可以像使用常规指针那样使用它们。 几乎所有良好的智能指针类都是模板类,包含其功能的泛型实现。小Demo之auto_ptrCSomeClass.h:ifndef CSOMECLASSdefine CSOMEC原创 2016-04-06 10:06:44 · 341 阅读 · 0 评论 -
map的坑
map的坑原创 2016-05-18 11:12:31 · 941 阅读 · 0 评论 -
C++网络
c++ socket原创 2016-05-10 19:31:02 · 670 阅读 · 1 评论 -
拷贝文件
//// io.cpp// firstcpp//// Created by 陈许兵 on 16/4/9.// Copyright © 2016年 陈许兵. All rights reserved.//#include #include using namespace std;bool copy(const char * src, const char * dest原创 2016-04-09 21:34:48 · 479 阅读 · 0 评论 -
partial_sort
代码include include include include using namespace std; int main() { array原创 2016-04-06 10:16:52 · 325 阅读 · 0 评论 -
sort
include include include include using namespace std;int main(){ array原创 2016-04-06 10:16:20 · 318 阅读 · 0 评论 -
lower_bound,upper_bound
代码include include include include using namespace std;int main() { std::vector data = { 1, 1, 2, 3, 3, 3, 3, 4, 4, 4, 5, 5, 6 };vector::iterator lower = std::lower_bound(data.begin(), data.end(), 1);原创 2016-04-06 10:15:51 · 281 阅读 · 0 评论 -
all_of, any_of, none_of
include include include include include include using namespace std; int main(){ vector v(10, 2); for(int n : v){ cout << n << ” “; } cout << endl;partial_sum(v.cbegin(), v.cend(), v.begin());cou原创 2016-04-06 10:15:14 · 459 阅读 · 0 评论 -
partial_sum
include include using namespace std;int main() { int val[] = {1,2,3,4,5}; int result[5];partial_sum (val, val+5, result); cout << “using default partial_sum: “; for (int i=0; i<5; i++) cout << res原创 2016-04-06 10:14:09 · 463 阅读 · 0 评论 -
智能指针之shared_ptr
shared_ptr的作用有如同指针,但会记录有多少个shared_ptrs共同指向一个对象。这便是所谓的引用计数(reference counting)。一旦最后一个这样的指针被销毁,也就是一旦某个对象的引用计数变为0,这个对象会被自动删除。这在非环形数据结构中防止资源泄露很有帮助。 shared_ptr最初实现于Boost库中,后来被C++标准委员会收录于TR1技术报告中,成为C++0x的一部原创 2016-04-06 10:13:37 · 494 阅读 · 0 评论 -
vector
includeincludeusing namespace std;void testvec1(){ vector vec; vector::iterator iter;vec.push_back(1); vec.push_back(2); vec.push_back(3); vec.push_back(4);for(iter = vec.begin(); iter != vec.end(原创 2016-04-06 10:13:10 · 403 阅读 · 0 评论 -
set
include include using namespace std;void test1() { set se; set::iterator iter;se.insert(1); se.insert(2); se.insert(3); se.insert(4); se.insert(2);for(iter = se.begin(); iter != se.end(); iter +原创 2016-04-06 10:12:44 · 393 阅读 · 0 评论 -
简单的文件读写
include include using namespace std;void TestReadFile(){ ifstream file; file.open(“C:/Users/Administrator/Desktop/cc.txt”, ios::in); if (file.fail()) { cout << “fail” << endl; return; } istreamb原创 2016-04-06 10:09:00 · 388 阅读 · 0 评论 -
map
map原创 2016-04-06 10:08:16 · 292 阅读 · 0 评论 -
list
include include using namespace std;void nomal() { list lis; list::iterator iter;lis.push_front(1); lis.push_front(2); lis.push_front(3); lis.push_front(4); lis.push_front(5); for(iter = lis.be原创 2016-04-06 10:07:44 · 355 阅读 · 0 评论 -
char*,const char*,string的相互转换
string char 各种转换原创 2016-04-06 10:05:17 · 462 阅读 · 0 评论