Function 什么是';在抛出';std::bad#u alloc'';什么意思?

Function 什么是';在抛出';std::bad#u alloc'';什么意思?,function,memory,vector,memory-leaks,ifstream,Function,Memory,Vector,Memory Leaks,Ifstream,我正在编写一个函数,它打开一个文本文件并读取每一行,将其添加到字符串向量中(每一行只有一个单词)。代码可以编译,但当我尝试运行它时,它会以错误终止 以下是调用函数并尝试打印向量后出现的错误: terminate called after throwing an instance of 'std::bad_alloc' what(): std::bad_alloc Aborted 如果调用函数但不打印向量,则会出现分段错误 我在网上查找了这个错误,但找不到它的确切含义。从我看到的情况来看,

我正在编写一个函数,它打开一个文本文件并读取每一行,将其添加到字符串向量中(每一行只有一个单词)。代码可以编译,但当我尝试运行它时,它会以错误终止

以下是调用函数并尝试打印向量后出现的错误:

terminate called after throwing an instance of 'std::bad_alloc'
  what():  std::bad_alloc
Aborted
如果调用函数但不打印向量,则会出现
分段错误

我在网上查找了这个错误,但找不到它的确切含义。从我看到的情况来看,这个错误似乎是由于使用了太多内存而引发的。也许我的代码中有某种东西导致了无限循环??这个错误到底意味着什么?它如何应用于我编写的代码

 vector<string> readToVector(string fileTo) {
        vector<string> setVector;
        string temp;
        ifstream openSet(fileTo.c_str());
        if (openSet.is_open()) {
            while ( getline (openSet,temp) ) {
                    setVector.push_back(temp);
            }
        }
        else {
            cout << "Unable to open set file." << endl;
        }
    }
vector readToVector(字符串fileTo){
向量集向量;
字符串温度;
ifstream openSet(fileTo.c_str());
if(openSet.is_open()){
while(getline(openSet,temp)){
设置向量推回(温度);
}
}
否则{

没关系,我很笨。我只是从来没有在我的函数中返回向量。facepalm