#include <algorithm>
#include <string>
#include <iostream>
#include <vector>
#include <iterator>
using namespace std;
//#include "ultis.h"
template<typename C>
void printContainer(const C& c,char delim=',',ostream &out=cout) {
printRange(c.begin(),c.end(),delim,out);
}
template <typename Fwd>
void printRange(Fwd first,Fwd last, char delim=',',ostream &out=cout) {
out<<"{";
while(first!=last) {
out<<*first;
if(++first!=last)
cout<<delim<<' ';
}
out<<"}"<<endl;
}
int main() {
vector<int> v;
back_insert_iterator<vector<int>> p = back_inserter(v);
for(int i=0;i<10;i++)
*p=i;
printContainer(v);
random_shuffle(v.begin(),v.end());
printContainer(v);
return 0;
}
==================================================================
--------------------Configuration: test6 - Win32 Debug--------------------
Compiling...
1.cpp
D:\VCSOURCEFILE\Foundation&App\test6\1.cpp(27) : error C2146: syntax error : missing ',' before identifier 'p'
D:\VCSOURCEFILE\Foundation&App\test6\1.cpp(27) : error C2065: 'p' : undeclared identifier
D:\VCSOURCEFILE\Foundation&App\test6\1.cpp(27) : error C2143: syntax error : missing '>' before ';'
D:\VCSOURCEFILE\Foundation&App\test6\1.cpp(27) : error C2679: binary '=' : no operator defined which takes a right-hand operand of type 'class std::back_insert_iterator<class std::vector<int,class std::allocator<int> > >' (or there is no acceptable
conversion)
D:\VCSOURCEFILE\Foundation&App\test6\1.cpp(29) : error C2100: illegal indirection
执行 cl.exe 时出错.
test6.exe - 1 error(s), 0 warning(s)
帮忙看一下一个的C++程序 编译出错
答案:1 悬赏:40 手机版
解决时间 2021-01-28 23:56
- 提问者网友:箛茗
- 2021-01-28 10:15
最佳答案
- 五星知识达人网友:胯下狙击手
- 2021-01-28 11:46
int main() {
vector<int> v;
back_insert_iterator<vector<int> > p = back_inserter(v);
for(int i=0;i<10;i++)
*p=i;
printContainer(v);
random_shuffle(v.begin(),v.end());
printContainer(v);
return 0;
}
vector<int> v;
back_insert_iterator<vector<int> > p = back_inserter(v);
for(int i=0;i<10;i++)
*p=i;
printContainer(v);
random_shuffle(v.begin(),v.end());
printContainer(v);
return 0;
}
我要举报
如以上回答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
点此我要举报以上问答信息
大家都在看
推荐资讯