zoukankan      html  css  js  c++  java
  • C++ 函数使用总结/编程注意事项

    1、stable_partition稳定划分和partition不稳定划分。 

    #include <iostream>
    #include <algorithm>
    #include <vector>
    using namespace std;
    
    struct Student 
    {
    	char name[20];
    		int age;
    };
    
    ostream & operator <<(ostream & os, const Student &s)
    {
    	os << "(" <<s.name <<" " <<s.age << ")";
    	return os;
    }
    
    bool AgeCom(Student & s)
    {
    	return s.age < 30;
    }
    
    int main(int argc, char *argv[])
    {
    	
    	Student stu[] = {{"ZhangSan",29},{"LiSi",57},{"WangWu",49},{"ZhaoLiu",27}};
    	copy(stu,stu+4,ostream_iterator<Student>(cout," "));
    	cout <<endl;
    
    	//不稳定的划分
    	vector<Student> vec(stu,stu+4);
    	partition(vec.begin(),vec.end(), AgeCom);
    	copy(vec.begin(),vec.end(),ostream_iterator<Student>(cout,""));
    	cout << endl;
    
    	//稳定的划分
    	vector<Student> vec2(stu,stu+4);
    	stable_partition(vec2.begin(),vec2.end(),AgeCom);
    	copy(vec.begin(),vec.end(),ostream_iterator<Student>(cout,""));
    	cout << endl;
    
    }
    

      

    2.TRACE宏

    TRACE不是函数而是一个宏,作用就是在调试器的输出窗口产生显示来自你的程序的消息。

    在debug下才有效,Release下是没用的,你可以把他看成printf 语句,不过这个语句在Release 下自动消失。

    3.STL Containers

    3.1 list中的方法如下:

    陆续更新中...

  • 相关阅读:
    InitializingBean
    线程池
    maven
    mysql主从库
    zookeeper
    分布式服务框架 Zookeeper -- 管理分布式环境中的数据
    远程调试
    enum
    注解
    Shell错误[: missing `]'
  • 原文地址:https://www.cnblogs.com/linlf03/p/2169460.html
Copyright © 2011-2022 走看看