📄 pr23012.cpp
字号:
////////////////////////////////////////
// File Name: pr23012.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;
// 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("Deer");
strVector2.push_back("Antelope");
strVector2.push_back("Turtle");
strVector2.push_back("Snake");
strVector2.push_back("Fish");
// Sort the vectors.
sort(strVector1.begin(), strVector1.end());
sort(strVector2.begin(), strVector2.end());
// 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;
// Search for the sorted range Deer, Fish, Snake.
bool result =
includes(strVector1.begin(), strVector1.end(),
strVector2.begin()+1, strVector2.begin()+3);
if (result)
std::cout << "Found sorted range." << std::endl;
else
std::cout << "Did not find sorted range." << std::endl;
return 0;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -