⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 pr23011.cpp

📁 c++编程宝典源码及Quincy99编译器 是《标准C++编程宝典》电子工业出版社的光盘
💻 CPP
字号:
////////////////////////////////////////
// File Name: pr23011.cpp
////////////////////////////////////////
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>

////////////////////////////////////////
// The function to be called by
// for_each().
////////////////////////////////////////
void show_val(string val)
{
    std::cout << val << std::endl;
}

////////////////////////////////////////
// The main() function.
////////////////////////////////////////
int main()
{
    // Create the vector objects.
    std::vector<string> strVector1;
    std::vector<string> strVector2;
    std::vector<string> strVector3(10);

    // Populate two vectors with values.
    strVector1.push_back("Zebra");
    strVector1.push_back("Deer");
    strVector1.push_back("Fish");
    strVector1.push_back("Snake");
    strVector1.push_back("Bat");

    strVector2.push_back("Cat");
    strVector2.push_back("Bird");
    strVector2.push_back("Turtle");
    strVector2.push_back("Horse");
    strVector2.push_back("Cow");

    // Display the contents of the vectors.
    std::cout << "Contents of vector1: " << std::endl;
    for_each(strVector1.begin(), strVector1.end(), show_val);
    std::cout << std::endl;

    std::cout << "Contents of vector2: " << std::endl;
    for_each(strVector2.begin(), strVector2.end(), show_val);
    std::cout << std::endl;

    // Sort the vectors.
    sort(strVector1.begin(), strVector1.end());
    sort(strVector2.begin(), strVector2.end());

    // Merge the sorted vectors.
    merge(strVector1.begin(), strVector1.end(),
          strVector2.begin(), strVector2.end(),
          strVector3.begin());

    // Display the contents of the new vector.
    std::cout << "Contents of vector3: " << std::endl;
    for_each(strVector3.begin(), strVector3.end(), show_val);

    return 0;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -