有C ++编译器问题吗?

如何解决有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 举报,一经查实,本站将立刻删除。

相关推荐


依赖报错 idea导入项目后依赖报错,解决方案:https://blog.csdn.net/weixin_42420249/article/details/81191861 依赖版本报错:更换其他版本 无法下载依赖可参考:https://blog.csdn.net/weixin_42628809/a
错误1:代码生成器依赖和mybatis依赖冲突 启动项目时报错如下 2021-12-03 13:33:33.927 ERROR 7228 [ main] o.s.b.d.LoggingFailureAnalysisReporter : *************************** APPL
错误1:gradle项目控制台输出为乱码 # 解决方案:https://blog.csdn.net/weixin_43501566/article/details/112482302 # 在gradle-wrapper.properties 添加以下内容 org.gradle.jvmargs=-Df
错误还原:在查询的过程中,传入的workType为0时,该条件不起作用 &lt;select id=&quot;xxx&quot;&gt; SELECT di.id, di.name, di.work_type, di.updated... &lt;where&gt; &lt;if test=&qu
报错如下,gcc版本太低 ^ server.c:5346:31: 错误:‘struct redisServer’没有名为‘server_cpulist’的成员 redisSetCpuAffinity(server.server_cpulist); ^ server.c: 在函数‘hasActiveC
解决方案1 1、改项目中.idea/workspace.xml配置文件,增加dynamic.classpath参数 2、搜索PropertiesComponent,添加如下 &lt;property name=&quot;dynamic.classpath&quot; value=&quot;tru
删除根组件app.vue中的默认代码后报错:Module Error (from ./node_modules/eslint-loader/index.js): 解决方案:关闭ESlint代码检测,在项目根目录创建vue.config.js,在文件中添加 module.exports = { lin
查看spark默认的python版本 [root@master day27]# pyspark /home/software/spark-2.3.4-bin-hadoop2.7/conf/spark-env.sh: line 2: /usr/local/hadoop/bin/hadoop: No s
使用本地python环境可以成功执行 import pandas as pd import matplotlib.pyplot as plt # 设置字体 plt.rcParams[&#39;font.sans-serif&#39;] = [&#39;SimHei&#39;] # 能正确显示负号 p
错误1:Request method ‘DELETE‘ not supported 错误还原:controller层有一个接口,访问该接口时报错:Request method ‘DELETE‘ not supported 错误原因:没有接收到前端传入的参数,修改为如下 参考 错误2:cannot r
错误1:启动docker镜像时报错:Error response from daemon: driver failed programming external connectivity on endpoint quirky_allen 解决方法:重启docker -&gt; systemctl r
错误1:private field ‘xxx‘ is never assigned 按Altʾnter快捷键,选择第2项 参考:https://blog.csdn.net/shi_hong_fei_hei/article/details/88814070 错误2:启动时报错,不能找到主启动类 #
报错如下,通过源不能下载,最后警告pip需升级版本 Requirement already satisfied: pip in c:\users\ychen\appdata\local\programs\python\python310\lib\site-packages (22.0.4) Coll
错误1:maven打包报错 错误还原:使用maven打包项目时报错如下 [ERROR] Failed to execute goal org.apache.maven.plugins:maven-resources-plugin:3.2.0:resources (default-resources)
错误1:服务调用时报错 服务消费者模块assess通过openFeign调用服务提供者模块hires 如下为服务提供者模块hires的控制层接口 @RestController @RequestMapping(&quot;/hires&quot;) public class FeignControl
错误1:运行项目后报如下错误 解决方案 报错2:Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.8.1:compile (default-compile) on project sb 解决方案:在pom.
参考 错误原因 过滤器或拦截器在生效时,redisTemplate还没有注入 解决方案:在注入容器时就生效 @Component //项目运行时就注入Spring容器 public class RedisBean { @Resource private RedisTemplate&lt;String
使用vite构建项目报错 C:\Users\ychen\work&gt;npm init @vitejs/app @vitejs/create-app is deprecated, use npm init vite instead C:\Users\ychen\AppData\Local\npm-