//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()函數(shù)和復(fù)制算法copy()函數(shù)?
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()函數(shù)?
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;
}
錯(cuò)誤提示:
>f:\visual?studio?projects\project1\project1\源.cpp(8):?error?C2143:?語(yǔ)法錯(cuò)誤:?缺少“;”(在“<”的前面)
1>f:\visual?studio?projects\project1\project1\源.cpp(8):?error?C4430:?缺少類(lèi)型說(shuō)明符?-?假定為?int。注意:?C++?不支持默認(rèn)?int
1>f:\visual?studio?projects\project1\project1\源.cpp(16):?error?C2065:?“OUTIT”:?未聲明的標(biāo)識(shí)符
1>f:\visual?studio?projects\project1\project1\源.cpp(16):?error?C2146:?語(yǔ)法錯(cuò)誤:?缺少“;”(在標(biāo)識(shí)符“out”的前面)
1>f:\visual?studio?projects\project1\project1\源.cpp(16):?error?C3861:?“out”:?找不到標(biāo)識(shí)符
1>f:\visual?studio?projects\project1\project1\源.cpp(18):?error?C2065:?“out”:?未聲明的標(biāo)識(shí)符
1>f:\visual?studio?projects\project1\project1\源.cpp(22):?error?C2065:?“out”:?未聲明的標(biāo)識(shí)符
==========?生成:?成功?0?個(gè),失敗?1?個(gè),最新?0?個(gè),跳過(guò)?0?個(gè)?==========
添加回答
舉報(bào)
0/150
提交
取消