向量下标超出范围错误,C

向量下标超出范围错误,C,第1张

概述当我尝试运行此程序时,我收到一个错误,该程序暂停程序并说“向量下标超出范围” 知道我做错了什么吗? #include <vector>#include <string>#include <iostream>#include <iomanip>#include <fstream>#include <sstream>using namespace std;//(int argc, ch 当我尝试运行此程序时,我收到一个错误,该程序暂停程序并说“向量下标超出范围”

知道我做错了什么吗?

#include <vector>#include <string>#include <iostream>#include <iomanip>#include <fstream>#include <sstream>using namespace std;//(int argc,char* argv[]int main(){    fstream bookread("test.txt");    vector<string> words;    bookread.open("test.txt");    if(bookread.is_open()){        cout << "opening textfile";        while(bookread.good()){            string input;            //getline(bookread,input);            bookread>>input;            //string cleaneDWord=preprocess(input);                     //char first=cleaneDWord[0];            //if(first<=*/            //cout << "getting words";            //getWords(words,input);        }    }    cout << "all done";    words[0];getchar();}
解决方法 你永远不会在单词vector中插入任何东西,所以行字[0];是非法的,因为它访问它的第一个元素,它不存在. 总结

以上是内存溢出为你收集整理的向量下标超出范围错误,C全部内容,希望文章能够帮你解决向量下标超出范围错误,C所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/langs/1255895.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-06-07
下一篇2022-06-07

发表评论

登录后才能评论

评论列表(0条)

    保存