//STL算法
#include<iostream>
#include<vector>
#include<algorithm>
#include<functional>
using namespace std;
typedef vector<int, allocator<int> >INTVEC;
typedef ostream_iterator< int, char, char_traits<char> >OUTIT;
int main()
{
int a[10] = { 35,56,79,80,45,10,4,125,67,80 };
int seed1 = 125;
int seed2 = 99;
//以下演示排序算法sort()函数和复制算法copy()函数
INTVEC vec1(a, a + 10);
OUTIT out(cout, "."); //ostream_iterator(cout,".")
cout << "vec1 befor sort(first,last)" << endl;
copy(vec1.begin(), vec1.end(), out);
cout << endl;
sort(vec1.begin(), vec1.end());
cout << "vec1 after sort(first,last)" << endl;
copy(vec1.begin(), vec1.end(), out);
cout << endl;
//以下演示查找算法find()函数
vector<int>::iterator iter1;
iter1 = find(vec1.begin(), vec1.end(), seed1);
if (iter1 == vec1.end()) {
cout << seed1 << "not found in vector" << endl;
}
else
{
cout << seed1 << "found in vector" << *iter1 << endl;
}
iter1 = find(vec1.begin(), vec1.end(), seed2);
if (iter1 == vec1.end()) {
cout << seed2 << "not found in vector" << endl;
}
else
{
cout << seed2 << "found in vector" << *iter1 << endl;
}
system("pause");
return 0;
}
错误提示:
>f:\visual studio projects\project1\project1\源.cpp(8): error C2143: 语法错误: 缺少“;”(在“<”的前面)
1>f:\visual studio projects\project1\project1\源.cpp(8): error C4430: 缺少类型说明符 - 假定为 int。注意: C++ 不支持默认 int
1>f:\visual studio projects\project1\project1\源.cpp(16): error C2065: “OUTIT”: 未声明的标识符
1>f:\visual studio projects\project1\project1\源.cpp(16): error C2146: 语法错误: 缺少“;”(在标识符“out”的前面)
1>f:\visual studio projects\project1\project1\源.cpp(16): error C3861: “out”: 找不到标识符
1>f:\visual studio projects\project1\project1\源.cpp(18): error C2065: “out”: 未声明的标识符
1>f:\visual studio projects\project1\project1\源.cpp(22): error C2065: “out”: 未声明的标识符
========== 生成: 成功 0 个,失败 1 个,最新 0 个,跳过 0 个 ==========
添加回答
举报
0/150
提交
取消