加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

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

发布时间:2020-12-16 03:27:29 所属栏目:百科 来源:网络整理
导读:当我尝试运行此程序时,我收到一个错误,该程序暂停程序并说“向量下标超出范围” 知道我做错了什么吗? #include vector#include string#include iostream#include iomanip#include fstream#include sstreamusing namespace std;//(int argc,char* argv[]int
当我尝试运行此程序时,我收到一个错误,该程序暂停程序并说“向量下标超出范围”

知道我做错了什么吗?

#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];是非法的,因为它访问它的第一个元素,它不存在.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读