帮忙看一下一个的C++程序 编译出错
#include<algorithm>#include<string>#include<iostream>#include<vector>#include<iterato...
#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) 展开
#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) 展开
1个回答
展开全部
int main() {
vector<int> v;
/* 这句出错了,两个>之间加个空格即可
back_insert_iterator<vector<int>> p = back_inserter(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);
*/
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;
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询