#include <iostream>
#include <string>
#include <map>
using namespace std;
#include <string>
#include <map>
using namespace std;
int main() {
string str;
map<string, int> ismap;
int i = 0;
while (1) {
cout << "输入字符串: ";
cin >> str;
if (str == "QUIT")
break;
int counter = ismap.count(str);
if (counter > 0)
cout << str << "在映射中曾经出现过" << counter << "次" << endl;
else
cout << str << "在映射中没有出现过" << endl;
ismap.insert(map<string, int>::value_type(str, i));
i ++;
}
return 0;
}
string str;
map<string, int> ismap;
int i = 0;
while (1) {
cout << "输入字符串: ";
cin >> str;
if (str == "QUIT")
break;
int counter = ismap.count(str);
if (counter > 0)
cout << str << "在映射中曾经出现过" << counter << "次" << endl;
else
cout << str << "在映射中没有出现过" << endl;
ismap.insert(map<string, int>::value_type(str, i));
i ++;
}
return 0;
}
#include <algorithm>
#include <iterator>
#include <vector>
#include <iostream>
#include <boost/array.hpp>
using namespace std;
#include <iterator>
#include <vector>
#include <iostream>
#include <boost/array.hpp>
using namespace std;
//将来自输入迭代器p的n个T类型的数值排序,将结果通过输出迭代器result输出
template<class T, class InputIterator, class OutputIterator>
void mySort(InputIterator first, InputIterator last, OutputIterator result) {
//通过输入迭代器p将输入数据存入向量容器s中
vector<T> s;
for (; first != last; ++first)
s.push_back(*first);
//对s进行排序,sort函数的参数必须是随机访问迭代器
sort(s.begin(), s.end());
//将s序列通过输出迭代器输出
copy(s.begin(), s.end(), result);
}
template<class T, class InputIterator, class OutputIterator>
void mySort(InputIterator first, InputIterator last, OutputIterator result) {
//通过输入迭代器p将输入数据存入向量容器s中
vector<T> s;
for (; first != last; ++first)
s.push_back(*first);
//对s进行排序,sort函数的参数必须是随机访问迭代器
sort(s.begin(), s.end());
//将s序列通过输出迭代器输出
copy(s.begin(), s.end(), result);
}
int main() {
//将s数组的内容排序后输出
boost::array<double, 5> a = { 1.2, 2.4, 0.8, 3.3, 3.2 };
mySort<double> (a.begin(), a.end(), ostream_iterator<double> (cout, " "));
cout << endl;
//从标准输入读入若干个整数,将排序后的结果输出
mySort<int> (istream_iterator<int> (cin), istream_iterator<int> (),
ostream_iterator<int> (cout, " "));
cout << endl;
return 0;
}
//将s数组的内容排序后输出
boost::array<double, 5> a = { 1.2, 2.4, 0.8, 3.3, 3.2 };
mySort<double> (a.begin(), a.end(), ostream_iterator<double> (cout, " "));
cout << endl;
//从标准输入读入若干个整数,将排序后的结果输出
mySort<int> (istream_iterator<int> (cin), istream_iterator<int> (),
ostream_iterator<int> (cout, " "));
cout << endl;
return 0;
}
#include <functional>
#include <iostream>
#include <vector>
#include <algorithm>
#include <boost/bind.hpp>
using namespace std;
#include <iostream>
#include <vector>
#include <algorithm>
#include <boost/bind.hpp>
using namespace std;
int main() {
int intArr[] = { 30, 90, 10, 40, 70, 50, 20, 80 };
const int N = sizeof(intArr) / sizeof(int);
vector<int> a(intArr, intArr + N);
vector<int>::iterator p = find_if(a.begin(), a.end(), bind(greater<int>(), _1, 40));
if (p == a.end())
cout << "no element greater than 40" << endl;
else
cout << "first element greater than 40 is: " << *p << endl;
return 0;
}
int intArr[] = { 30, 90, 10, 40, 70, 50, 20, 80 };
const int N = sizeof(intArr) / sizeof(int);
vector<int> a(intArr, intArr + N);
vector<int>::iterator p = find_if(a.begin(), a.end(), bind(greater<int>(), _1, 40));
if (p == a.end())
cout << "no element greater than 40" << endl;
else
cout << "first element greater than 40 is: " << *p << endl;
return 0;
}