如何解决有C ++编译器问题吗?
#include <iostream>
#include <vector>
using namespace std;
int main(){
vector<int> books;
int n,b;
cin>>n;
for(int i=0; i<n; ++i){
cin >> b;
books.push_back(b);
}
for(auto i=books.begin(); i!= books.end(); ++i)
cout<< *i << " ";
cout<<endl;
return 0;
}
为什么运行此程序时出现错误?有人可以向我解释一下,因为我检查过,我的代码很完美。
当我在C ++ 14(在CodeChef上)的在线编译器中运行此代码时,它工作正常。我需要在笔记本电脑中使用编译器进行更新吗?还是语法有变化?
CMD错误:
tryc.cpp: In function 'int main()': tryc.cpp:16:14: error: 'i' does
not name a type
for(auto i=books.begin(); i!= books.end(); ++i)
^ tryc.cpp:16:31: error: expected ';' before 'i'
for(auto i=books.begin(); i!= books.end(); ++i)
^ tryc.cpp:16:31: error: name lookup of 'i' changed for ISO 'for' scoping [-fpermissive] tryc.cpp:16:31: note:
(if you use '-fpermissive' G++ will accept your code) tryc.cpp:16:32:
error: no match for 'operator!=' (operand types are 'int' and
'std::vector<int>::iterator {aka __gnu_cxx::__normal_iterator<int*,std::vector<int> >}')
for(auto i=books.begin(); i!= books.end(); ++i)
^ tryc.cpp:16:32: note: candidates are: In file included from
c:\mingw\lib\gcc\mingw32\4.8.1\include\c++\iosfwd:40:0,from c:\mingw\lib\gcc\mingw32\4.8.1\include\c++\ios:38,from c:\mingw\lib\gcc\mingw32\4.8.1\include\c++\ostream:38,from c:\mingw\lib\gcc\mingw32\4.8.1\include\c++\iostream:39,from tryc.cpp:1: c:\mingw\lib\gcc\mingw32\4.8.1\include\c++\bits\postypes.h:221:5:
note: template<class _StateT> bool std::operator!=(const
std::fpos<_StateT>&,const std::fpos<_StateT>&)
operator!=(const fpos<_StateT>& __lhs,const fpos<_StateT>& __rhs)
^ c:\mingw\lib\gcc\mingw32\4.8.1\include\c++\bits\postypes.h:221:5:
note: template argument deduction/substitution failed:
tryc.cpp:16:45: note: mismatched types 'const std::fpos<_StateT>'
and 'int'
for(auto i=books.begin(); i!= books.end(); ++i)
^ In file included from c:\mingw\lib\gcc\mingw32\4.8.1\include\c++\bits\stl_algobase.h:64:0,from c:\mingw\lib\gcc\mingw32\4.8.1\include\c++\bits\char_traits.h:39,from c:\mingw\lib\gcc\mingw32\4.8.1\include\c++\ios:40,from tryc.cpp:1: c:\mingw\lib\gcc\mingw32\4.8.1\include\c++\bits\stl_pair.h:227:5:
note: template<class _T1,class _T2> bool std::operator!=(const
std::pair<_T1,_T2>&,const std::pair<_T1,_T2>&)
operator!=(const pair<_T1,_T2>& __x,const pair<_T1,_T2>& __y)
^ c:\mingw\lib\gcc\mingw32\4.8.1\include\c++\bits\stl_pair.h:227:5:
note: template argument deduction/substitution failed:
tryc.cpp:16:45: note: mismatched types 'const std::pair<_T1,_T2>'
and 'int'
for(auto i=books.begin(); i!= books.end(); ++i)
^ In file included from c:\mingw\lib\gcc\mingw32\4.8.1\include\c++\bits\stl_algobase.h:67:0,from tryc.cpp:1: c:\mingw\lib\gcc\mingw32\4.8.1\include\c++\bits\stl_iterator.h:303:5:
note: template<class _Iterator> bool std::operator!=(const
std::reverse_iterator<_Iterator>&,const
std::reverse_iterator<_Iterator>&)
operator!=(const reverse_iterator<_Iterator>& __x,^ c:\mingw\lib\gcc\mingw32\4.8.1\include\c++\bits\stl_iterator.h:303:5:
note: template argument deduction/substitution failed:
tryc.cpp:16:45: note: mismatched types 'const
std::reverse_iterator<_Iterator>' and 'int'
for(auto i=books.begin(); i!= books.end(); ++i)
^ In file included from c:\mingw\lib\gcc\mingw32\4.8.1\include\c++\bits\stl_algobase.h:67:0,from tryc.cpp:1: c:\mingw\lib\gcc\mingw32\4.8.1\include\c++\bits\stl_iterator.h:353:5:
note: template<class _IteratorL,class _IteratorR> bool
std::operator!=(const std::reverse_iterator<_Iterator>&,const
std::reverse_iterator<_IteratorR>&)
operator!=(const reverse_iterator<_IteratorL>& __x,^ c:\mingw\lib\gcc\mingw32\4.8.1\include\c++\bits\stl_iterator.h:353:5:
note: template argument deduction/substitution failed:
tryc.cpp:16:45: note: mismatched types 'const
std::reverse_iterator<_Iterator>' and 'int'
for(auto i=books.begin(); i!= books.end(); ++i)
^ In file included from c:\mingw\lib\gcc\mingw32\4.8.1\include\c++\string:41:0,from c:\mingw\lib\gcc\mingw32\4.8.1\include\c++\bits\locale_classes.h:40,from c:\mingw\lib\gcc\mingw32\4.8.1\include\c++\bits\ios_base.h:41,from c:\mingw\lib\gcc\mingw32\4.8.1\include\c++\ios:42,from tryc.cpp:1: c:\mingw\lib\gcc\mingw32\4.8.1\include\c++\bits\allocator.h:138:5:
note: template<class _T1,class _T2> bool std::operator!=(const
std::allocator<_CharT>&,const std::allocator<_T2>&)
operator!=(const allocator<_T1>&,const allocator<_T2>&)
^ c:\mingw\lib\gcc\mingw32\4.8.1\include\c++\bits\allocator.h:138:5:
note: template argument deduction/substitution failed:
tryc.cpp:16:45: note: mismatched types 'const
std::allocator<_CharT>' and 'int'
for(auto i=books.begin(); i!= books.end(); ++i)
^ In file included from c:\mingw\lib\gcc\mingw32\4.8.1\include\c++\string:41:0,from tryc.cpp:1: c:\mingw\lib\gcc\mingw32\4.8.1\include\c++\bits\allocator.h:143:5:
note: template<class _Tp> bool std::operator!=(const
std::allocator<_CharT>&,const std::allocator<_CharT>&)
operator!=(const allocator<_Tp>&,const allocator<_Tp>&)
^ c:\mingw\lib\gcc\mingw32\4.8.1\include\c++\bits\allocator.h:143:5:
note: template argument deduction/substitution failed:
tryc.cpp:16:45: note: mismatched types 'const
std::allocator<_CharT>' and 'int'
for(auto i=books.begin(); i!= books.end(); ++i)
^ In file included from c:\mingw\lib\gcc\mingw32\4.8.1\include\c++\string:52:0,from tryc.cpp:1: c:\mingw\lib\gcc\mingw32\4.8.1\include\c++\bits\basic_string.h:2532:5:
note: template<class _CharT,class _Traits,class _Alloc> bool
std::operator!=(const std::basic_string<_CharT,_Traits,_Alloc>&,const std::basic_string<_CharT,_Alloc>&)
operator!=(const basic_string<_CharT,_Alloc>& __lhs,^ c:\mingw\lib\gcc\mingw32\4.8.1\include\c++\bits\basic_string.h:2532:5:
note: template argument deduction/substitution failed:
tryc.cpp:16:45: note: mismatched types 'const
std::basic_string<_CharT,_Alloc>' and 'int'
for(auto i=books.begin(); i!= books.end(); ++i)
^ In file included from c:\mingw\lib\gcc\mingw32\4.8.1\include\c++\string:52:0,from tryc.cpp:1: c:\mingw\lib\gcc\mingw32\4.8.1\include\c++\bits\basic_string.h:2544:5:
note: template<class _CharT,class _Alloc> bool
std::operator!=(const _CharT*,_Alloc>&)
operator!=(const _CharT* __lhs,^ c:\mingw\lib\gcc\mingw32\4.8.1\include\c++\bits\basic_string.h:2544:5:
note: template argument deduction/substitution failed:
tryc.cpp:16:45: note: mismatched types 'const _CharT*' and 'int'
for(auto i=books.begin(); i!= books.end(); ++i)
^ In file included from c:\mingw\lib\gcc\mingw32\4.8.1\include\c++\string:52:0,from tryc.cpp:1: c:\mingw\lib\gcc\mingw32\4.8.1\include\c++\bits\basic_string.h:2556:5:
note: template<class _CharT,const _CharT*)
operator!=(const basic_string<_CharT,^ c:\mingw\lib\gcc\mingw32\4.8.1\include\c++\bits\basic_string.h:2556:5:
note: template argument deduction/substitution failed:
tryc.cpp:16:45: note: mismatched types 'const
std::basic_string<_CharT,_Alloc>' and 'int'
for(auto i=books.begin(); i!= books.end(); ++i)
^ In file included from c:\mingw\lib\gcc\mingw32\4.8.1\include\c++\bits\locale_facets.h:48:0,from c:\mingw\lib\gcc\mingw32\4.8.1\include\c++\bits\basic_ios.h:37,from c:\mingw\lib\gcc\mingw32\4.8.1\include\c++\ios:44,from tryc.cpp:1: c:\mingw\lib\gcc\mingw32\4.8.1\include\c++\bits\streambuf_iterator.h:210:5:
note: template<class _CharT,class _Traits> bool std::operator!=(const
std::istreambuf_iterator<_CharT,_Traits>&,const
std::istreambuf_iterator<_CharT,_Traits>&)
operator!=(const istreambuf_iterator<_CharT,_Traits>& __a,^ c:\mingw\lib\gcc\mingw32\4.8.1\include\c++\bits\streambuf_iterator.h:210:5:
note: template argument deduction/substitution failed:
tryc.cpp:16:45: note: mismatched types 'const
std::istreambuf_iterator<_CharT,_Traits>' and 'int'
for(auto i=books.begin(); i!= books.end(); ++i)
^ In file included from c:\mingw\lib\gcc\mingw32\4.8.1\include\c++\vector:64:0,from tryc.cpp:2: c:\mingw\lib\gcc\mingw32\4.8.1\include\c++\bits\stl_vector.h:1427:5:
note: template<class _Tp,class _Alloc> bool std::operator!=(const
std::vector<_Tp,const std::vector<_Tp,_Alloc>&)
operator!=(const vector<_Tp,_Alloc>& __x,const vector<_Tp,_Alloc>& __y)
^ c:\mingw\lib\gcc\mingw32\4.8.1\include\c++\bits\stl_vector.h:1427:5:
note: template argument deduction/substitution failed:
tryc.cpp:16:45: note: mismatched types 'const std::vector<_Tp,_Alloc>' and 'int'
for(auto i=books.begin(); i!= books.end(); ++i)
^ In file included from c:\mingw\lib\gcc\mingw32\4.8.1\include\c++\mingw32\bits\c++allocator.h:33:0,from c:\mingw\lib\gcc\mingw32\4.8.1\include\c++\bits\allocator.h:46,from c:\mingw\lib\gcc\mingw32\4.8.1\include\c++\string:41,from tryc.cpp:1: c:\mingw\lib\gcc\mingw32\4.8.1\include\c++\ext\new_allocator.h:144:5:
note: template<class _Tp> bool __gnu_cxx::operator!=(const
__gnu_cxx::new_allocator<_Tp>&,const __gnu_cxx::new_allocator<_Tp>&)
operator!=(const new_allocator<_Tp>&,const new_allocator<_Tp>&)
^ c:\mingw\lib\gcc\mingw32\4.8.1\include\c++\ext\new_allocator.h:144:5:
note: template argument deduction/substitution failed:
tryc.cpp:16:45: note: mismatched types 'const
__gnu_cxx::new_allocator<_Tp>' and 'int'
for(auto i=books.begin(); i!= books.end(); ++i)
^ In file included from c:\mingw\lib\gcc\mingw32\4.8.1\include\c++\bits\stl_algobase.h:67:0,from tryc.cpp:1: c:\mingw\lib\gcc\mingw32\4.8.1\include\c++\bits\stl_iterator.h:823:5:
note: template<class _Iterator,class _Container> bool
__gnu_cxx::operator!=(const __gnu_cxx::__normal_iterator<_Iterator,_Container>&,const __gnu_cxx::__normal_iterator<_Iterator,_Container>&)
operator!=(const __normal_iterator<_Iterator,_Container>& __lhs,^ c:\mingw\lib\gcc\mingw32\4.8.1\include\c++\bits\stl_iterator.h:823:5:
note: template argument deduction/substitution failed:
tryc.cpp:16:45: note: mismatched types 'const
__gnu_cxx::__normal_iterator<_Iterator,_Container>' and 'int'
for(auto i=books.begin(); i!= books.end(); ++i)
^ In file included from c:\mingw\lib\gcc\mingw32\4.8.1\include\c++\bits\stl_algobase.h:67:0,from tryc.cpp:1: c:\mingw\lib\gcc\mingw32\4.8.1\include\c++\bits\stl_iterator.h:817:5:
note: template<class _IteratorL,class _IteratorR,class _Container>
bool __gnu_cxx::operator!=(const
__gnu_cxx::__normal_iterator<_IteratorL,const __gnu_cxx::__normal_iterator<_IteratorR,_Container>&)
operator!=(const __normal_iterator<_IteratorL,^ c:\mingw\lib\gcc\mingw32\4.8.1\include\c++\bits\stl_iterator.h:817:5:
note: template argument deduction/substitution failed:
tryc.cpp:16:45: note: mismatched types 'const
__gnu_cxx::__normal_iterator<_IteratorL,_Container>' and 'int'
for(auto i=books.begin(); i!= books.end(); ++i)
^ tryc.cpp:17:17: error: invalid type argument of unary '*' (have 'int')
cout<< *i << " ";
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。