首页 文章 精选 留言 我的

精选列表

搜索[c 11],共10000篇文章
优秀的个人博客,低调大师

《C++标准程序库》读书笔记(四)

, 复制代码 #include <iostream> #include <list> #include <algorithm> using namespace std; int main() { list<int> coll; list<int>::iterator pos25,pos35,pos; for(int i=20;i<=40;++i) coll.push_back(i); pos25 = find(coll.begin(),coll.end(),25); pos35 = find(coll.begin(),pos25,35); if(pos35!=pos25) {//pos35在pos25前 pos = find(coll.begin(),pos25,30); } else {//pos25在pos35前 pos = find(pos25,coll.end(),30); } cout<<"num: "<<*pos<<endl; system("pause"); return 0; } 复制代码 使用仿函数 复制代码 #include <functional> /* class for the compose_f_gx_hx adapter*/ template <class OP1, class OP2, class OP3> class compose_f_gx_hx_t : public std::unary_function<typename OP2::argument_type, typename OP1::result_type> { private: OP1 op1; // process: op1(op2(x),op3(x)) OP2 op2; OP3 op3; public: // constructor compose_f_gx_hx_t (const OP1& o1, const OP2& o2, const OP3& o3) : op1(o1), op2(o2), op3(o3) { } // function call typename OP1::result_type operator()(const typename OP2::argument_type& x) const { return op1(op2(x),op3(x)); } }; /* convenience function for the compose_f_gx_hx adapter*/ template <class OP1, class OP2, class OP3> inline compose_f_gx_hx_t<OP1,OP2,OP3> compose_f_gx_hx (const OP1& o1, const OP2& o2, const OP3& o3) { return compose_f_gx_hx_t<OP1,OP2,OP3>(o1,o2,o3); } 复制代码 复制代码 #include <iostream> #include <list> #include <algorithm> #include <functional> #include "compose21.hpp" using namespace std; int main() { list<int> coll; list<int>::iterator pos; for(int i=20;i<=40;++i) coll.push_back(i); pos = find_if(coll.begin(),coll.end(), compose_f_gx_hx(logical_or<bool>(), bind2nd(equal_to<int>(),25), bind2nd(equal_to<int>(),35))); cout<<"num: "<<*pos<<endl; system("pause"); return 0; } 复制代码 2,三种迭代器适配器: 1) Insert iterator 插入位置可以是容器的最前或最后,或是在某一特定位置上. 复制代码 #include <iostream> #include <vector> #include <list> #include <deque> #include <set> #include <algorithm> using namespace std; int main() { list<int> coll1; // insert elements from 1 to 9 into the first collection for (int i=1; i<=9; ++i) { coll1.push_back(i); } // copy the elements of coll1 into coll2 by appending them vector<int> coll2; copy (coll1.begin(), coll1.end(), // source back_inserter(coll2)); // destination // copy the elements of coll1 into coll3 by inserting them at the front // - reverses the order of the elements deque<int> coll3; copy (coll1.begin(), coll1.end(), // source front_inserter(coll3)); // destination // copy elements of coll1 into coll4 // - only inserter that works for associative collections set<int> coll4; copy (coll1.begin(), coll1.end(), // source inserter(coll4,coll4.begin())); // destination return 0; } 复制代码 back_inserter的内部调用push_back(),在容器尾端插入元素,只有在提供有push_back()成员函数的容器中才能使用,这样的容器有:vector,deque,list. front_inserter的内部调用push_front(),在容器最前端插入元素,只有在提供有push_ front()成员函数的容器中才能使用,这样的容器有deque和list;一般性的inserter,作用是将元素插入”初始化时接受之第二参数”所指的位置的前方.它内部调用insert(). 2)Stream iterator.这是用来读写流的迭代器. 复制代码 #include <iostream> #include <vector> #include <string> #include <algorithm> #include <iterator> using namespace std; int main() { vector<string> coll; copy (istream_iterator<string>(cin), // start of source istream_iterator<string>(), // end of source back_inserter(coll)); // destination sort (coll.begin(), coll.end()); unique_copy (coll.begin(), coll.end(), // source ostream_iterator<string>(cout,"\n")); // destination } 复制代码 3)Reverse iterator 复制代码 #include <iostream> #include <vector> #include <algorithm> #include <iterator> using namespace std; int main() { vector<int> coll; // insert elements from 1 to 9 for (int i=1; i<=9; ++i) { coll.push_back(i); } // print all element in reverse order copy (coll.rbegin(), coll.rend(), // source ostream_iterator<int>(cout," ")); // destination cout << endl; } 复制代码 3,移除元素 复制代码 #include <iostream> #include <list> #include <algorithm> #include <iterator> using namespace std; int main() { list<int> coll; // insert elements from 6 to 1 and 1 to 6 for (int i=1; i<=6; ++i) { coll.push_front(i); coll.push_back(i); } // print all elements of the collection copy (coll.begin(), coll.end(),ostream_iterator<int>(cout," ")); cout << endl; list<int>::iterator end = remove (coll.begin(), coll.end(),3);//新的尾节点 // print resulting elements of the collection copy (coll.begin(), end,ostream_iterator<int>(cout," ")); cout << endl; // print number of resulting elements cout << "number of removed elements: "<< distance(end,coll.end()) << endl; // remove ``removed'' elements coll.erase (end, coll.end()); // print all elements of the modified collection copy (coll.begin(), coll.end(),ostream_iterator<int>(cout," ")); cout << endl; } 复制代码 本文转自Phinecos(洞庭散人)博客园博客,原文链接:http://www.cnblogs.com/phinecos/archive/2008/08/27/1278096.html,如需转载请自行联系原作者

优秀的个人博客,低调大师

C#返回以数字日期编号为日期函数

/// <summary> /// 返回以数字日期编号为日期函数 /// </summary> /// <returns>日期编号</returns> public DateTime GetCodeToDate(string MyDateCode) { try // 正常运行 { String strYear = MyDateCode.Substring(0, 4); String strMonth = MyDateCode.Substring(4, 2); String strDay = MyDateCode.Substring(6, 2); // 返回日期 return Convert.ToDateTime(strYear.ToString() + "-" + strMonth.ToString() + "-" + strDay.ToString()); } catch (System.Exception Exp) // 异常处理 { // 异常信息 System.Diagnostics.Debug.Write(Exp.Message.ToString()); // 返回日期 return DateTime.Today; } } 我有几张阿里云幸运券分享给你,用券购买或者升级阿里云相应产品会有特惠惊喜哦!把想要买的产品的幸运券都领走吧!快下手,马上就要抢光了。 https://promotion.aliyun.com/ntms/act/ambassador/sharetouser.html?userCode=6evata1e&utm_source=6evata1e

优秀的个人博客,低调大师

Xamarin向iOS和Android引入C# Async支持

Xamarin引入支持iOS和Android异步开发的库,现在已经发布了一个预览版本。该库主要基于微软的.NET 4.5,而后者是作为Visual Studio 2012的一部分于去年发布的。Xamarin是之前人们所熟知的MonoTouch和Mono for Android开发平台的新名字。 作为最初的Xamarin 2.0的一部分,该移动平台采用了Mono和.NET中的类库。而之前的MonoTouch和Mono for Android仅限于以Silverlight/Moonlight为基础的一个子集。Rodrigo Kumpera写道: 尽管异步是该版本的主题,但我们也将这两年来的改进打包到Mono运行时中了,覆盖了目前可支持Android、Mac和iOS用户的超过7000次提交。 该版本也带来了它对iOS脚本批处理编译器的改进。与其他大多数平台不同,iOS不允许以JIT编译方式生成代码。这给动态调用的代码带来了问题,尤其是涉及泛型的时候。 在iOS上,我们目前为值类型生成“可共享的代码(shareable code)”,这是代码生成技术方面的一项革命性创新。在实践中,这意味着之前会提示“Attempting to JIT compile method”并崩溃的一整段代码现在能够正常工作了。在提供我们所能推断出的高性能、微调过的泛型代码的同时——比如直接调用Foo(T x)方法——我们会为Foo(T x)生成一个值类型的共享版本,可用于之前会失败的动态场景下。曾经的梦想变为了现实。 目前微软的.NET中自有的JIT编译器并没有这种能力。尽管所有引用类型可以共享一个方法,但不同值类型的泛型方法必须重新编译。 .NET 4.0引入的协变和逆变支持也已通过一些方式进入到Xamarin平台。 本文来自云栖社区合作伙伴“doNET跨平台”,了解相关信息可以关注“opendotnet”微信公众号

优秀的个人博客,低调大师

(转载)Objective-C多个UIButton同时点击问题

今天看到一个有趣的属性,可以避免同一个界面上的多个button同时点击。于是就想把这篇博文记录下来,为了尊重原作者,把原文地址贴在前面。 原文地址:http://blog.csdn.net/liu1347508335/article/details/50617644 一个页面的两个或者多个button如果不设置的话是可以同时点击的,如果事件冲突的话就会出问题,如“发送”和“取消”。一些push操作也会push多个页面,交互十分不友好。解决方法是设置button的exclusiveTouch为YES。 button.exclusiveTouch = YES; ExclusiveTouch的作用是:可以达到同一界面上多个控件接受事件时的排他性,从而避免一些问题。也就是说避免在一个界面上同时点击多个button。 如果一个页面的button太多的话一个一个设置会比较麻烦,可以这样: -(void)setExclusiveTouchForButtons:(UIView *)myView { for (UIView * button in [myView subviews]) { if([button isKindOfClass:[UIButton class]]) [((UIButton *)button) setExclusiveTouch:YES]; else if ([button isKindOfClass:[UIView class]]){ [self setExclusiveTouchForButtons:button]; } } } 但是这样需要在每个控制器都要设置。可以采用一句话来代替这样的设置,在AppDelegate中添加: [[UIButton appearance] setExclusiveTouch:YES]; 有人可能不知道模拟器怎么模拟两根手指同时点击的事件,补充一下:按住option键调节两根手指的距离,再按住Shift键调整两根手指的位置(option键不要放开);这样就模拟点击屏幕上任意两点的位置。

资源下载

更多资源
优质分享App

优质分享App

近一个月的开发和优化,本站点的第一个app全新上线。该app采用极致压缩,本体才4.36MB。系统里面做了大量数据访问、缓存优化。方便用户在手机上查看文章。后续会推出HarmonyOS的适配版本。

Mario

Mario

马里奥是站在游戏界顶峰的超人气多面角色。马里奥靠吃蘑菇成长,特征是大鼻子、头戴帽子、身穿背带裤,还留着胡子。与他的双胞胎兄弟路易基一起,长年担任任天堂的招牌角色。

Spring

Spring

Spring框架(Spring Framework)是由Rod Johnson于2002年提出的开源Java企业级应用框架,旨在通过使用JavaBean替代传统EJB实现方式降低企业级编程开发的复杂性。该框架基于简单性、可测试性和松耦合性设计理念,提供核心容器、应用上下文、数据访问集成等模块,支持整合Hibernate、Struts等第三方框架,其适用范围不仅限于服务器端开发,绝大多数Java应用均可从中受益。

Sublime Text

Sublime Text

Sublime Text具有漂亮的用户界面和强大的功能,例如代码缩略图,Python的插件,代码段等。还可自定义键绑定,菜单和工具栏。Sublime Text 的主要功能包括:拼写检查,书签,完整的 Python API , Goto 功能,即时项目切换,多选择,多窗口等等。Sublime Text 是一个跨平台的编辑器,同时支持Windows、Linux、Mac OS X等操作系统。

用户登录
用户注册
修改密码
忘记密码