如何修复'for'循环没有停止
How to fix 'for' loops didn't stop
我正在制作一个名为 score
的int
数组,但for
循环无法正常工作(我认为循环没有停止(。
我试图删除cin >> score[i]
,然后变为正常。
array<int, 9> score;
cout << "Score graphics from 1 to tennn";
for(int i = 0; i <= score.size(); i++){
cout << "The number of people who get " << i + 1 << " : ";
cin >> score[i];
}
我希望输出The number of people who get 1 : (input)
到The number of people who get 10 : (input)
this:
for(int i = 0; i <= score.size(); i++){
应该是:
for(int i = 0; i < score.size(); i++){
由于score.size()
将返回9
,但数组的最后索引是8
。
&nbsp;
使用您的原始代码,循环的最后运行将在访问带有太大索引的数组时调用一些不确定的行为:
cin >> score[9]; // score array only goes from 0 to 8!!
相关文章:
- "error: no matching function for call to"构造函数错误
- 表示"accepting anything for this template argument" C++概念的通配符
- 如何在C++中从两个单独的for循环中添加两个数组
- 在Linux for Windows上编译C++代码时出错
- 静态数据成员的问题-修复链接错误会导致编译器错误
- 调用专用模板时出错"no matching function for call to [...]"
- Python中的for循环与C++有何不同
- 如何修复输出日志中的"EnableInput can only be specified on a Pawn for its Controller"错误
- 如何修复以下错误"no match for call to '(std::tr1::shared_ptr<_iobuf*>) (FILE*&)'"
- 如何修复 C++ 中的"no matching fuction for call to:"错误
- 如何修复从基类继承两次时"error: no matching function for call to"
- 如何修复'for'循环没有停止
- 如何修复C++中的"no match for operator+"?
- 如何修复错误消息,如"argument list for class template is missing"?
- Eclipse IDE for C/C++:找不到二进制文件,修复混乱
- 如何修复 WSL 上的智能感知'A definition for the symbol could not be located'
- 如何修复" no match for 'operator<<' in 'std::cout"错误?
- 基于范围的循环与 for-each 循环有何不同
- OpenMP 不会在不同的线程中运行这个 for 循环,我该如何修复它
- 如何修复"error: no previous declaration for void awn::vala_array_destroy"?