<1>auto ,initializer_list<T>,auto指向函数指针的简易,和typdef 定义的类型执行函数指针有多复杂。

  1. #include <iostream>
  2. #include <initializer_list>
  3. #include <string>
  4. using namespace std;
  5.  
  6. template <typename T>
  7. T sum(initializer_list<T> rh)
  8. {
  9. T val;
  10. for(auto p= rh.begin();p!=rh.end();p++)
  11. {
  12. val+= *p;
  13. }
  14. return val;
  15. }
  16.  
  17. int main()
  18. {
  19. // use init list
  20. cout << sum({,,,,}) <<endl;
  21. cout << sum({1.0,2.0,3.1,4.0,5.0}) <<endl;
  22.  
  23. //
  24. cout << "use auto to point the function sum" <<endl;
  25. auto dadd_func = sum<double>;
  26. auto iadd_func = sum<int>;
  27. auto tadd_func = sum<string>;
  28. cout << dadd_func({,,,}) <<endl;
  29. cout << iadd_func({,,,,}) <<endl;
  30. cout << tadd_func({"houdini","maya","json"}) <<endl;
  31.  
  32. cout << "\nuse the typedef to pointer\n";
  33. typedef int (*td_int_sum)(initializer_list<int> rh);
  34. typedef string (*td_str_sum)(initializer_list<string> rh);
  35. td_int_sum int_add = sum<int>;
  36. td_str_sum str_add = sum<string>;
  37. cout << int_add({,,,,,}) <<endl;
  38. cout << str_add({"s1","s2","s5"}) << endl;
  39.  
  40. return ;
  41. }

<2>funcional,std::generate,std::count_if

  1. #include <iostream>
  2. #include <math.h>
  3. #include <vector>
  4. #include <algorithm>
  5. #include <functional>
  6.  
  7. using namespace std;
  8.  
  9. double square(double x){return x*x;}
  10.  
  11. int main()
  12. {
  13. vector <int> vars();
  14.  
  15. generate(vars.begin(),vars.end(),std::rand);
  16. for_each(vars.begin(),vars.end(),[](int v){cout << v <<endl;});
  17.  
  18. // lambda can transfer local variable
  19. int sum = ;
  20. for_each(vars.begin(),vars.end(),[&sum](int v){sum+=v;});
  21. cout << "the sum is " << sum <<endl;
  22.  
  23. // <100 num
  24. cout << "get <100 numbers" <<endl;
  25. cout << count_if(vars.begin(),vars.end(),[](int v){ return v<;}) <<endl;
  26.  
  27. // functional
  28. function<double(double)> ef1 = square;
  29. cout << ef1() <<endl; //
  30.  
  31. function<void(int var)> ef2 = [](int val){cout << val <<endl;};
  32. ef2(); //
  33.  
  34. return ;
  35. }

<3> remove_if,vector,min_element,max_element

  1. include <iostream>
  2. #include <algorithm>
  3. #include <vector>
  4. #include <string>
  5. using namespace std;
  6.  
  7. void cppRemove_if()
  8. {
  9. cout << "====cppRemove_if====\n";
  10. int myInts[]{,,,,,,,}; // 1 2 3 4 5 6 7 8
  11. int *pbegin = myInts;
  12. int *pend = myInts + sizeof(myInts)/ sizeof(int);
  13. pend = remove_if(pbegin,pend,
  14. [](const int &val)->bool{return val% == ;});//2 4 5 8 ? ? ? ?
  15. for (int* p=pbegin; p!=pend; ++p)
  16. cout << ' ' << *p;
  17. cout << "\n";
  18. cout << "====cppRemove_if====\n";
  19.  
  20. }
  21.  
  22. int main()
  23. {
  24.  
  25. vector<int> va{,,,,,};
  26.  
  27. // find, if not find elements,will return last *iter;
  28. auto va_find2 = find(va.begin(),va.end(),);
  29. auto va_find2e = find_if(va.begin(),va.end(),[](const int &x){return x==;});
  30. cout << *va_find2 <<endl;
  31. cout << *va_find2e <<endl;
  32.  
  33. cout << *min_element(va.begin(),va.end()) <<endl;
  34. cout << *max_element(va.begin(),va.end()) <<endl;
  35.  
  36. auto min_max = minmax_element(va.begin(),va.end());
  37. cout << "min val:" <<*(min_max.first)<<endl;
  38. cout << "max val:" <<*(min_max.second)<<endl;
  39.  
  40. cout << "remove the second elements \n";
  41. va.erase(va.begin()+,va.begin()+);
  42. for_each(va.begin(),va.end(),[](const int &x){cout << x <<endl;});
  43.  
  44. cout << "remove by condition <5 \n";
  45. va.erase(remove_if(va.begin(),va.end(),[](int x){return x <;}),va.end());
  46. for_each(va.begin(),va.end(),[](const int &x){cout << x <<endl;});
  47.  
  48. cppRemove_if();
  49. return ;
  50. }

<4>binary_search,sort更加详细的用法:

  1. #include <iostream>
  2. #include <algorithm>
  3. #include <vector>
  4. #include <functional>
  5. using namespace std;
  6.  
  7. template <typename T1>
  8. void ShowIntArray(const T1 begin, const T1 end)
  9. {
  10. for_each(begin,end,[](const int &x){cout << x <<" "; });
  11. cout << "\n";
  12. }
  13. template <typename T>
  14. void ShowSTLArray(const T&cont)
  15. {
  16. auto iter = cont.begin();
  17. auto end = cont.end();
  18. for(;iter!=end;iter++)
  19. {
  20. cout << *iter <<" ";
  21. }
  22. cout <<endl;
  23. };
  24.  
  25. void cpp_sort()
  26. {
  27. int a[]= {,,,,,};
  28. int *begin = a;
  29. int *end = a + ;
  30.  
  31. cout << "before sort:\n";
  32. ShowIntArray(begin, end);
  33.  
  34. sort(begin,end);
  35. cout << "after sort:\n";
  36. ShowIntArray(begin, end);
  37.  
  38. cout << "from large to small:\n";
  39. sort(begin,end,[](const int &x,const int &y){return x>y;});
  40. ShowIntArray(begin, end);
  41.  
  42. cout << "from small to large use less<int>():\n";
  43. sort(begin,end,less<int>());
  44. ShowIntArray(begin, end);
  45.  
  46. cout << "from large to small use greater<int>():\n";
  47. sort(begin,end,greater<int>());
  48. ShowIntArray(begin, end);
  49.  
  50. vector<string> vecStr{"Got","cool","features"};
  51. cout << "sort the sting array:\n";
  52. ShowSTLArray(vecStr);
  53. auto strCmp = [](string &a,string &b)
  54. {
  55. return a.length() > b.length();
  56. };
  57. cout << "sort the array results:\n";
  58. sort(vecStr.begin(),vecStr.end(),strCmp);
  59. ShowSTLArray(vecStr);
  60.  
  61. }
  62.  
  63. void cpp_binary_search()
  64. {
  65.  
  66. cout << "=======search 01:==========\n";
  67. std::vector<int> haystack {, , , , };
  68. std::vector<int> needles {, , };
  69. sort(haystack.begin(),haystack.end());
  70. for (auto needle : needles)
  71. {
  72. cout << "Searching for " << needle << '\n';
  73. if (binary_search(haystack.begin(), haystack.end(), needle))
  74. {
  75.  
  76. cout << "Found " << needle << '\n';
  77. }
  78. else
  79. {
  80. cout << "no dice!\n";
  81. }
  82. }
  83. cout << "=======search 01:==========\n";
  84.  
  85. std::vector<int> haystack2 {, , , , ,,,};
  86. sort(haystack2.begin(),haystack2.end(),[](int &x,int &y){return x<y;});
  87. ShowSTLArray(haystack2);
  88.  
  89. auto func =[](int i,int j)->bool{cout<< "i:" << i; cout << " j:"<<j;cout<<"\n";return (i<j);};
  90. if (binary_search(haystack2.begin(),haystack2.end(),,func))
  91. {
  92. cout << "found 5" <<endl;
  93. }
  94.  
  95. }
  96.  
  97. int main()
  98. {
  99. //cpp_sort();
  100. cpp_binary_search();
  101. return ;
  102. }

binarySearch结果:

Sort结果:

 <5> 线程大法

(1) hello world thread:

  1. #include <iostream>
  2. #include <thread>
  3. #include <memory>
  4. using namespace std;
  5.  
  6. void thread_task()
  7. {
  8. cout << "thread hello world\n";
  9. }
  10.  
  11. int main()
  12. {
  13. shared_ptr<thread> t(new thread(thread_task));
  14. t->join();
  15.  
  16. return ;
  17. }

(2)带参数的函数(bind方法,直接使用thread构造也可以)

  1. void thread_parm(const int &n,const string& name)
  2. {
  3. for(int i=;i<n;i++)
  4. {
  5. cout << name <<":thread loop in " << i <<endl;
  6. }
  7. }
  8.  
  9. void withParam()
  10. {
  11. thread t0(thread_parm,,"houdini");
  12. thread t1(bind(thread_parm,,"maya"));
  13. t0.join();
  14. t1.join();
  15. }
  16.  
  17. int main()
  18. {
  19. withParam();
  20. return ;
  21. }

(3)成员对象函数执行在线程中(也可以作用到智能指针对象)

  1. class HelloObject
  2. {
  3. public:
  4. void sayHello(const string& name,int n)
  5. {
  6. for(int i=;i<n;i++)
  7. {
  8. cout << name << " thread: " << i <<endl;
  9. }
  10. }
  11. };
  12.  
  13. void objectFunction()
  14. {
  15. HelloObject obj;
  16. thread t(&HelloObject::sayHello,&obj,"Json",);
  17. t.join();
  18.  
  19. // work with shared_ptr
  20. shared_ptr<HelloObject> objPtr(new HelloObject());
  21. thread tptr(&HelloObject::sayHello,objPtr,"Houdini",);
  22. tptr.join();
  23. }
  24.  
  25. int main()
  26. {
  27. objectFunction();
  28. return ;
  29. }

(4)传递引用,头文件functional,std::ref()

  1. class FuncObj
  2. {
  3. public:
  4. void operator()()const
  5. {
  6. cout << this <<endl;
  7. }
  8. };
  9. void passRef()
  10. {
  11. auto obj = FuncObj();
  12. obj();
  13.  
  14. //pass by value
  15. cout << "thread will pass by value\n";
  16. thread t1(obj);
  17. t1.join();
  18.  
  19. //pass by ref
  20. cout << "thread will pass by ref\n";
  21. thread t2(ref(obj));
  22. t2.join();
  23.  
  24. }
  25.  
  26. int main()
  27. {
  28. passRef();
  29. return ;
  30. }

结果:

0x22fdff
thread will pass by value
0x7c6150
thread will pass by ref
0x22fdff

普通的函数也可以

  1. void increment(int &value)
  2. {
  3. value++ ;
  4. cout << "value :" << value <<endl;
  5.  
  6. }
  7. void passRef2()
  8. {
  9. int a = ;
  10. thread t(increment,ref(a));
  11. t.join();
  12. }
  13.  
  14. int main()
  15. {
  16. passRef2();
  17. return ;
  18. }

(5)基本功能:

匿名函数:get_id() 区分线程

  1. void lambdaTest()
  2. {
  3. vector <thread> threads;
  4. for(int i=;i<;i++)
  5. {
  6. threads.emplace_back(thread([](){cout << "thread id " << this_thread::get_id() << endl;}));
  7. }
  8.  
  9. for(auto &t : threads)
  10. {
  11. t.join();
  12. }
  13. }
  14.  
  15. int main()
  16. {
  17. lambdaTest();
  18. return ;
  19. }

总线程数:

  1. cout << thread::hardware_concurrency() <<endl;

(6)异常与线程

标准处理方法

  1. struct Counter2
  2. {
  3. int value;
  4. Counter2():value(){}
  5. void increment()
  6. {
  7. ++value;
  8. }
  9. void decrement()
  10. {
  11. if(value == )
  12. {
  13. throw string("value cannot be less than 0");
  14. }
  15.  
  16. --value;
  17. }
  18. };
  19.  
  20. struct Wrapper
  21. {
  22. Counter2 ct;
  23. mutex m;
  24.  
  25. void increment()
  26. {
  27.  
  28. }
  29. void decrement()
  30. {
  31. m.lock();
  32. try
  33. {
  34. ct.decrement();
  35. }
  36. catch (const string &e)
  37. {
  38. m.unlock();
  39. cout << e <<endl;
  40. throw e;
  41. }
  42.  
  43. m.unlock();
  44. }
  45. };
  46.  
  47. void exceptionLock()
  48. {
  49. Wrapper wap;
  50. wap.ct.value = ;
  51.  
  52. vector<thread> threads;
  53. for(int i=;i<;i++)
  54. {
  55. threads.emplace_back(thread([&wap](){
  56. wap.decrement();
  57.  
  58. }));
  59. }
  60. for(auto &t:threads)
  61. {
  62. t.join();
  63. }
  64. cout << wap.ct.value << endl;
  65. }

(7)模仿Inter TBB parallel_for

串行时间:87

并行时间:19

  1. struct BlockRange
  2. {
  3. BlockRange():begin(),end()
  4. {
  5.  
  6. }
  7. int begin;
  8. int end;
  9. };
  10.  
  11. class ApplyFoo
  12. {
  13. public:
  14. ApplyFoo(vector<int> *data):mData(data)
  15. {
  16. }
  17. void operator()(const BlockRange &range)const
  18. {
  19. for(int i=range.begin;i<range.end;i++)
  20. {
  21. (*mData)[i] += ;
  22. }
  23. }
  24. private:
  25. vector<int> *mData;
  26. };
  27.  
  28. template <typename T>
  29. void parallel_for(const T &body,int size,int begin)
  30. {
  31. auto nThreads = thread::hardware_concurrency();
  32. auto nValuesSize = size;
  33. auto perBlockSize =nValuesSize / nThreads;
  34. if(nValuesSize < nThreads)
  35. {
  36. BlockRange range;
  37. range.begin = begin;
  38. range.end = nValuesSize;
  39. body(range);
  40. return;
  41. }
  42. // building blocks
  43. vector<BlockRange> blocks;
  44. int index = begin;
  45. while(index <= nValuesSize)
  46. {
  47. BlockRange range;
  48. range.begin = index;
  49. range.end = index+ perBlockSize;
  50. blocks.push_back(range);
  51. index += (perBlockSize) ;
  52. }
  53. // fix last block end size;
  54. blocks[blocks.size()-].end = nValuesSize;
  55. // thread pool to run
  56. typedef shared_ptr<thread> thread_ptr;
  57. vector<thread_ptr> pools;
  58. for(BlockRange&r:blocks)
  59. {
  60. pools.emplace_back(new thread(body,r));
  61. }
  62. for(auto &t:pools)
  63. {
  64. t->join();
  65. }
  66.  
  67. }
  68.  
  69. void parallel()
  70. {
  71. vector<int> values();
  72. fill(values.begin(),values.end(),);
  73.  
  74. double start,end,cost;
  75. start=clock();
  76. parallel_for(ApplyFoo(&values),values.size(),);
  77. end= clock();
  78. cost = end -start;
  79. cout << "parallel for cost time:" << cost <<endl;
  80.  
  81. }
  82. void serial()
  83. {
  84. vector<int> values();
  85. fill(values.begin(),values.end(),);
  86.  
  87. double start,end,cost;
  88. start=clock();
  89. for(int i=;i<values.size();i++)
  90. {
  91. values[i] += ;
  92. }
  93. end= clock();
  94. cost = end -start;
  95. cout << "serial for cost time:" << cost <<endl;
  96. }
  97.  
  98. int main()
  99. {
  100.  
  101. parallel();
  102. serial();
  103. return ;
  104. }

并行accumulation:

10亿个元素相加:简直他妈的快飞起来了。

串行时间:13063

并行时间:1023

  1. #include <vector>
  2. #include <time.h>
  3. #include <iostream>
  4. #include <thread>
  5. #include <algorithm>
  6. using namespace std;
  7.  
  8. struct BlockRange
  9. {
  10. BlockRange():begin(),end(),id()
  11. {
  12.  
  13. }
  14. int begin;
  15. int end;
  16. int id;
  17. };
  18.  
  19. class ApplyFoo
  20. {
  21. public:
  22. ApplyFoo(vector<int> *data):mData(data)
  23. {
  24. }
  25. void operator()(const BlockRange &range,vector<int> *des)const
  26. {
  27. auto value = int();
  28. for(int i=range.begin;i<range.end;i++)
  29. {
  30. value +=(*mData)[i];
  31. }
  32. (*des)[range.id] = value;
  33. }
  34. private:
  35. vector<int> *mData;
  36.  
  37. };
  38.  
  39. template <typename retType,typename T>
  40. retType parallel_add(const T &body,int size,int begin)
  41. {
  42. vector<retType> partial_accum;
  43. auto nThreads = thread::hardware_concurrency();
  44. auto nValuesSize = size;
  45. auto perBlockSize =nValuesSize / nThreads;
  46. if(nValuesSize < nThreads)
  47. {
  48. partial_accum.resize();
  49. BlockRange range;
  50. range.begin = begin;
  51. range.end = nValuesSize;
  52. range.id = ;
  53. body(range,&partial_accum);
  54. return accumulate(partial_accum.begin(),partial_accum.end(),retType());
  55. }
  56. // building blocks
  57. vector<BlockRange> blocks;
  58. int index = begin;
  59. int blockId = ;
  60. while(index <= nValuesSize)
  61. {
  62. BlockRange range;
  63. range.begin = index;
  64. range.end = index+ perBlockSize;
  65. range.id = blockId;
  66. blocks.push_back(range);
  67. index += (perBlockSize) ;
  68. blockId += ;
  69. }
  70. partial_accum.resize(blocks.size());
  71.  
  72. // fix last block end size;
  73. blocks[blocks.size()-].end = nValuesSize;
  74. // thread pool to run
  75. typedef shared_ptr<thread> thread_ptr;
  76. vector<thread_ptr> pools;
  77.  
  78. for(BlockRange&r:blocks)
  79. {
  80. pools.emplace_back(new thread(body,r,&partial_accum));
  81. }
  82. for(auto &t:pools)
  83. {
  84. t->join();
  85. }
  86.  
  87. return accumulate(partial_accum.begin(),partial_accum.end(),retType());
  88.  
  89. }
  90.  
  91. void parallel()
  92. {
  93. vector<int> values();
  94. fill(values.begin(),values.end(),);
  95.  
  96. double start,end,cost;
  97. start=clock();
  98. cout << "get the result :" <<parallel_add<int>(ApplyFoo(&values),values.size(),) <<endl;
  99. end= clock();
  100. cost = end -start;
  101. cout << "parallel for cost time:" << cost <<endl;
  102. }
  103.  
  104. void serial()
  105. {
  106. vector<int> values();
  107. fill(values.begin(),values.end(),);
  108.  
  109. double start,end,cost;
  110. start=clock();
  111. cout << "get the result :" <<accumulate(values.begin(),values.end(),) <<endl;
  112. end= clock();
  113. cost = end -start;
  114. cout << "parallel for cost time:" << cost <<endl;
  115. }
  116.  
  117. int main()
  118. {
  119.  
  120. parallel();
  121. //serial();
  122. return ;
  123. }

<n> boost bind

  1. #include <boost/bind.hpp>
  2. #include <boost/shared_ptr.hpp>
  3.  
  4. #include <iostream>
  5. using namespace std;
  6. void dprint(int x,int y)
  7. {
  8. cout << x << " " <<y <<endl;
  9. }
  10.  
  11. class Bind_test
  12. {
  13. public:
  14. void setData(int x,int y)
  15. {
  16. _x = x;
  17. _y = y;
  18. }
  19. void printData()
  20. {
  21. cout << _x << " " <<_y <<endl;
  22. }
  23. private:
  24. int _x;
  25. int _y;
  26.  
  27. };
  28.  
  29. void increnum(int &dg)
  30. {
  31. dg++;
  32. }
  33.  
  34. int main()
  35. {
  36. boost::bind(&dprint,,)(); // 5,5
  37. boost::bind(&dprint,,_1)(); // 3, 5
  38. boost::bind(&dprint,_1,_1)(); // 2, 2
  39. boost::bind(&dprint,_1,_2)(,); // 1, 2
  40. boost::bind(&dprint,_2,_1)(,); // 2, 1 ->函数参数对掉
  41.  
  42. cout << "\nbind the class function\n";
  43. boost::shared_ptr<Bind_test> bclass(new Bind_test);
  44. boost::bind(&Bind_test::setData,bclass,,)();
  45. bclass->printData();
  46.  
  47. Bind_test *bclass_02 = new Bind_test;
  48. boost::bind(&Bind_test::setData,bclass_02,,)();
  49. bclass_02->printData(); // 2 ,3
  50. delete bclass_02;
  51.  
  52. Bind_test bclass_03;
  53. boost::bind(&Bind_test::setData,&bclass_03,,)();
  54. bclass_03.printData(); // 4 ,5
  55. boost::bind(&Bind_test::setData,&bclass_03,_1,_1)();
  56. bclass_03.printData(); // 9 ,9
  57. boost::bind(&Bind_test::setData,&bclass_03,_1,_2)(,);
  58. bclass_03.printData(); // 9 ,10
  59.  
  60. int dgNum = ;
  61. boost::bind(&increnum,boost::ref(dgNum))(); // 类似C++11 Thread 里要传递引用std::ref(x)
  62. cout << dgNum <<endl;
  63.  
  64. cin.get();
  65. return ;
  66. }

额外的:

static_assert 编译时候assertions

下面将输出:hello \n no

  1. cout << R"(hello \n no)" <<endl;

1,Boost -> Bind的更多相关文章

  1. boost::bind

    bind并不是一个单独的类或函数,而是非常庞大的家族,依据绑定的参数个数和要绑定的调用对象类型,总共有十个不同的形式,但它们的名字都叫bind. bind接受的第一个参数必须是一个可调用对象f,包括函 ...

  2. boost::bind 和 boost::function 基本用法

    这是一篇介绍bind和function用法的文章,起因是近来读陈硕的文章,提到用bind和function替代继承,于是就熟悉了下bind和function的用法,都是一些网上都有的知识,记录一下,期 ...

  3. 以boost::function和boost:bind取代虚函数

    转自:http://blog.csdn.net/Solstice/archive/2008/10/13/3066268.aspx 这是一篇比较情绪化的blog,中心思想是“继承就像一条贼船,上去就下不 ...

  4. (转)boost::bind介绍

    转自:http://www.cnblogs.com/sld666666/archive/2010/12/14/1905980.html 这篇文章介绍boost::bind()的用法, 文章的主要内容是 ...

  5. boost::bind实践2——来自《Beyond the C++ Standard Library ( An Introduction to Boost )》

    直接代码: 代码段1: #include <iostream> #include <string> #include <boost/bind/bind.hpp> c ...

  6. boost::bind实践

    第一部分源码为基础实践: /*Beyond the C++ Standard Library ( An Introduction to Boost )[CN].chm*/ /*bind的用法*/ #i ...

  7. 关于boost::function与boost::bind函数的使用心得

    最近开始写一个线程池,期间想用一个通用的函数模板来使得各个线程执行不同的任务,找到了Boost库中的function函数. Boost::function是一个函数包装器,也即一个函数模板,可以用来代 ...

  8. [转] [翻译]图解boost::bind

    http://kelvinh.github.io/blog/2013/12/03/boost-bind-illustrated/ 其实这是很久之前留的一个坑了,一直没有填.. 记得在刚开始看到 boo ...

  9. 使用BOOST BIND库提高C++程序性能

    Boost.Bind为函数和函数对象,值语义和指针提供语义了一致的语法.我们首先通过一些简单的例子来看看它的基本用法,之后我们会延伸到嵌套绑定以实现功能组合.理解bind用法的一个关键是理解占位符(p ...

随机推荐

  1. 关于iis8.5中发布的网站无法连接数据库的解决方案。

    发布的网站在浏览时出现如下提示: “/”应用程序中的服务器错误. 在与 SQL Server 建立连接时出现与网络相关的或特定于实例的错误.未找到或无法访问服务器.请验证实例名称是否正确并且 SQL ...

  2. Apache增加Basic Auth

    在.htaccess文件中增加 AuthUserFile /var/www/htpasswd/test.htpasswd AuthName EnterPassword AuthType Basic r ...

  3. hadoop2.7下载mirror

    http://mirror.bit.edu.cn/apache/hadoop/common/

  4. shell 条件判断

    一.数值判断 INT1 -eq INT2           INT1和INT2两数相等为真 INT1 -ne INT2           INT1和INT2两数不等为真 INT1 -gt INT2 ...

  5. python jenkins-api,jira crowd. email-servers

    jenkins  user authentication: http://stackoverflow.com/questions/15411208/authenticate-jenkins-users ...

  6. Linux基本操作命令

    Linux基本操作命令 首先介绍一个名词“控制台(console)”,它就是我们通常见到的使用字符操作界面的人机接口,例如dos.我们说控制台命令,就是指通过字符界面输入的可以操作系统的命令,例如do ...

  7. CSS之伪元素

    1. :first-line 向元素的首行文本添加样式,不必关心首行是元素节点还是文本节点 <style> body,htm,div,p{ margin:0; padding:0; } d ...

  8. 各种同步方法性能比较(synchronized,ReentrantLock,Atomic)

    synchronized: 在资源竞争不是很激烈的情况下,偶尔会有同步的情形下,synchronized是很合适的.原因在于,编译程序通常会尽可能的进行优化synchronize,另外可读性非常好,不 ...

  9. Windows RabbitMQ 命令

    启动: 后台运行:rabbitmq-server -detached D:\Program Files\RabbitMQ Server\rabbitmq_server-3.6.6\sbin>ra ...

  10. C++学习笔记 四种新式类型转换

    static_cast ,dynamic_cast,const_cast,reinterpret_cast static_cast 定义:通俗的说就是静态显式转换,用于基本的数据类型转换,及指针之间的 ...