89 lines
2.2 KiB
C++
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#include <algorithm>
#include <iostream>
#include <iterator>
#include <string>
#include <vector>
#include "pics.h"
using std::cout;
using std::copy;
using std::endl;
using std::ostream_iterator;
using std::string;
using std::vector;
int main()
{
vector<string> p;
p.push_back("this is an");
p.push_back("example");
p.push_back("to");
p.push_back("illustrate");
p.push_back("framing");
ostream_iterator<string>ofile(cout, "\n");
copy(p.begin(), p.end(), ofile);
cout << endl;
vector<string> f = frame(p);
copy(f.begin(), f.end(), ofile); cout << endl;
vector<string> h = hcat(p,frame(p));
copy(h.begin(), h.end(), ofile);
cout << endl;
return 0;
}
#include <algorithm> // 引入标准算法库用于std::copy等算法
#include <iostream> // 引入标准输入输出流库
#include <iterator> // 引入迭代器库用于std::ostream_iterator
#include <string> // 引入字符串库
#include <vector> // 引入动态数组vector容器库
#include "pics.h" // 引入自定义头文件提供frame和hcat函数的声明
using std::cout; // 引入标准输出对象
using std::copy; // 引入标准拷贝算法
using std::endl; // 引入标准换行符
using std::ostream_iterator; // 引入输出流迭代器
using std::string; // 引入标准字符串类
using std::vector; // 引入标准向量类
int main()
{
// 定义一个存储字符串的vector并向其中添加多行字符串
vector<string> p;
p.push_back("this is an"); // 添加字符串到vector
p.push_back("example");
p.push_back("to");
p.push_back("illustrate");
p.push_back("framing");
// 定义输出流迭代器用于将vector内容输出到标准输出
ostream_iterator<string> ofile(cout, "\n");
// 输出vector p的内容到终端
copy(p.begin(), p.end(), ofile);
cout << endl; // 输出一个空行分隔内容
// 调用frame函数为vector p添加边框并返回新vector
vector<string> f = frame(p);
// 输出带边框的vector内容
copy(f.begin(), f.end(), ofile);
cout << endl; // 输出一个空行分隔内容
// 调用hcat函数将原始vector p与带边框的vector f水平连接
vector<string> h = hcat(p, frame(p));
// 输出水平连接后的vector内容
copy(h.begin(), h.end(), ofile);
cout << endl; // 输出一个空行分隔内容
return 0; // 程序结束
}