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

📄 pr24007.cpp

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

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

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

    // 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;
    std::for_each(strVector1.begin(),
        strVector1.end(), show_val);
    std::cout << std::endl;

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

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

    // Merge the sorted vectors to cout.
    std::merge(strVector1.begin(), strVector1.end(),
          strVector2.begin(), strVector2.end(),
          std::ostream_iterator<std::string>(std::cout));

    return 0;
}

⌨️ 快捷键说明

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