C++进程以状态 -1073741819 终止
C++ Process terminated with status -1073741819
我正在创建一个小字典。我创建了一个字符串向量来预先打印一些单词,以将其中一个作为用户的输入并向他们描述单词。
我尝试在谷歌上搜索它,并试图在 for 循环中设置unsigned int i = 0
。
下面给出了这样做的代码部分:
#include <iostream>
#include <string>
#include <vector>
using namespace std;
int main()
{
vector<string> word = {"none", "jump fatigue" , "scrim game", "box up", "turtling", "swing", "flickshot", "tracking", "panic build", "cone jump", "ttv", "one-shot", "tagged", "blue", "white", "lasered", "melted", "default", "bot", "stealth", "aggresive", "sweaty", "tryhard", "choke"};
for(int i = 0; i <= word.size(); i++){
cout<<i<<")"<< word[i] << endl;
}
return 0;
}
它打印没有任何错误,在运行代码结束时,它会冻结一段时间并结束, Process terminated with status -1073741819(0 minute(s), 4 second(s))
而它应该以 0 终止
在调试代码时,我得到 warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
您的问题出在 for 循环i <= word.size()
中。这应该是<
.最后一个索引将比大小小 1,因为第一个索引为 0。
我建议至少在 for 循环中使用 size_t
以获得更好的类型
for (std::size_t i = 0; i < word.size(); i++) {
尽管更简洁的迭代方式是基于范围的 for 循环
for (auto& w : word) {
std::cout << w << 'n';
}
相关文章:
- OpenGL - 在抛出"__gnu_cxx::recursive_init_error"实例后终止调用?
- 多个文件的内存分配错误"在抛出 'std :: bad_alloc' what (): std :: bad_alloc 的实例后终止调用" [C++]
- 我收到以下错误:抛出'std::bad_alloc'实例后终止调用
- 为什么这个 c++ 代码打印出长度 5,当我打印出字符串时,程序会自动终止?
- 当我在其中一个线程执行中(在activemq-cpp中)捕获到特定值时,我如何终止/停止所有其他线程
- llvm构建器向基本块添加终止符
- 如何使用隔离>终止执行来停止所有线程
- 用于将C++代码转换为 Web 程序集的脚本未终止
- C++应用程序 MySQL odbc 数据库连接错误:在引发"otl_tmpl_exception<>"实例后终止调用
- 终止 QProcess 不会终止子进程
- 运行代码时,c++ 会终止进程
- 检测到堆栈粉碎:已终止 中止(核心已转储)
- 在输入句子时终止 std::out_of_range
- 二进制搜索的终止点
- MPI:检查是否有任何进程已终止
- 英特尔 TBB 程序不会终止,可能会误用参考计数器
- 如何改进我的代码,使其不会因超时而终止?(黑客排名挑战)
- while 循环不以哨兵值终止
- C++进程以状态 -1073741819 终止
- 我的链接列表程序在代码块编译器(X0000000005)中以状态-1073741819终止