20170812

来源:互联网 发布:中经商品交易中心软件 编辑:程序博客网 时间:2024/05/16 06:59
/********************************************************//*                        sort排序                      *//********************************************************///#include<iostream>//#include<vector>//#include<algorithm>//using namespace std;//int main()//{//    vector<int>v;//    v.push_back(13);//    v.push_back(23);//    v.push_back(03);//    v.push_back(233);//    v.push_back(113);//    sort(v.begin(), v.end());//    for (auto s : v)//        cout << s <<endl;//    system("pause");//    return 0;//}/********************************************************//*                  从大到小sort排序                    *//********************************************************///#include<iostream>//#include<vector>//#include<algorithm>//#include <functional>  //greater等仿函数的头文件//using namespace std;////bool SortFunction(int a, int b)//{//    return a > b;//}//int main()//{//    vector<int>v;//    v.push_back(13);//    v.push_back(23);//    v.push_back(3);//    v.push_back(233);//    v.push_back(113);//    //sort(v.begin(), v.end(),SortFunction);//    sort(v.begin(), v.end(),greater<int>());//    for (auto s : v)//        cout << s <<endl;//    system("pause");//    return 0;//}/********************************************************//*                 对结构体成员排序                     *//********************************************************///#include <iostream>//#include <vector>//#include <algorithm>////using namespace std;//////struct Test//{//    int a, b;//}TT;//////重写排序函数,从大到小排序//bool SortFunction(Test a, Test b)//{//    return a.a > b.a;//}//////重载运算符 输出结构体数据//ostream& operator << (ostream &os, Test&tt)//{//    os << tt.a << endl;//    return os;//}//int main()//{//    //测试迭代器//    vector<int> as;//    vector<int>::iterator ast;//    for (int i = 0; i < 10; ++i)//    {//        as.push_back(i);//    }//    for ( ast = as.begin(); ast != as.end(); ++ast)//        cout << *ast << endl;//    //    //测试输出结构体//    vector<Test> vs;//    vector<Test>::iterator t;//    Test a, b, c, d;//    a.a = 234;//    b.a = 452;//    c.a = 98;//    d.a = 53;//    vs.push_back(a);//    vs.push_back(b);//    vs.push_back(c);//    vs.push_back(d);//    sort(vs.begin(), vs.end(), SortFunction);//    for (t= vs.begin(); t != vs.end();++t)//       cout << *t <<endl;//    return 0;//}/********************************************************//*                 对类成员排序                     *//********************************************************///#include <iostream>//#include <algorithm>//#include <functional>//#include <vector>//using namespace std;////class myclass {//public://    myclass(int a, int b) :first(a), second(b){}//    int first;//    int second;//    bool operator < (const myclass &m)const //    {//        return first < m.first;//    }//};////bool less_second(const myclass & m1, const myclass & m2) //{//    return m1.second < m2.second;//}////int main() {////    vector< myclass > vect;//    for (int i = 0; i < 10; i++)//    {//        myclass my(10 - i, i * 3);//        vect.push_back(my);//    }//    for (int i = 0; i < vect.size(); i++)//        cout << "(" << vect[i].first << "," << vect[i].second << ")\n";//    //    //以第一个数据升序排序//    sort(vect.begin(), vect.end());//    cout << "after sorted by first:" << endl;//    for (int i = 0; i < vect.size(); i++)//        cout << "(" << vect[i].first << "," << vect[i].second << ")\n";//    //    //以第二个数据降序排序//    sort(vect.begin(), vect.end(), less_second);//    cout << "after sorted by second:" << endl;//    for (int i = 0; i < vect.size(); i++)//        cout << "(" << vect[i].first << "," << vect[i].second << ")\n";////    return 0;//}//strcpy#include <assert.h>  #include <iostream>using namespace std;char * Strcpy(char* dest, const char* src){    assert(dest != NULL&&src != NULL);    char* res = dest;    //char aa = *dest++;   //指针后移1位  输出为?23abc 第一个位置存放的是随机值,共占用13个位置      while ((*dest++ = *src++) != '\0');    return res;}int main(){    char a[] = "1,2,3,a,b,c";    char d[14];    Strcpy(d, a);    cout << d;    system("pause");    return 0;}