小编cha*_*rli的帖子

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

当我尝试运行此程序时,我收到一个错误,该程序暂停程序并说"向量下标超出范围"

知道我做错了什么吗?

#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();
}
Run Code Online (Sandbox Code Playgroud)

c++ file vector

6
推荐指数
1
解决办法
2万
查看次数

标签 统计

c++ ×1

file ×1

vector ×1