C++ 错误:"cannot find bounds of current function"



我在编程 c++ 方面仍然很新 - 所以如果我的代码还不完美,请原谅我(我仍然愿意接受任何改进;)的建议)

我在运行此代码时遇到问题(仅是较大项目的一部分)。

int stock::import(string file){
ifstream input;
input.open(file.c_str());

input.ignore(100000, 'n');
while(!input.eof()){
int y = 0;
int m = 0;
int d = 0;
string year;
string month;
string day;
string open;
string high;
string low;
string close;
string volume;
string adj;

{
getline(input, year, '-');
y = atoi(year.c_str());
}
{
getline(input, month, '-');
m = atoi(month.c_str());
}
{
getline(input, day, ',');
d = atoi(day.c_str());
}

int index = findplace(y, m, d);

values[index].year = y;
values[index].month = m;
values[index].day = d;
{
getline(input, open, ',');
values[index].open = open;
}

{
getline(input, high, ',');
values[index].high = high;
}
{
getline(input, low, ',');
values[index].low = low;
}
{
getline(input, close, ',');
values[index].close = close;
}
{
getline(input, volume, ',');
values[index].volume = volume;
}
{
getline(input, adj, 'n');
values[index].adj = adj;
}

}
return 0;}

项目编译良好,但由于调用函数"import",我的程序立即崩溃。调试器在代码的这一部分给我错误"找不到当前函数的绑定":

{
getline(input, open, ',');
values[index].open = open;
}

奇怪的是,如果我删除这部分代码:

{
getline(input, year, '-');
y = atoi(year.c_str());
}

几行显示我的程序工作正常的关键部分(这意味着它不会崩溃,但当然不会做它应该做的事情)。

我目前正在将代码块作为 IDE 取消。

谁能帮我解决这个问题?我现在真的很绝望,因为我已经尝试了我所知道的一切......

正如这里建议的,是关于值和findplace()的更多信息:

class stock{
private:
string name = "";
string code = "";
string number = "";
stock* next = NULL;
int findplace(int year, int month, int day);
public:
day* values = new day[30];
stock(string c);
string getindex();
void setnext(stock* n);
stock* getnext();
int import(string file);
};

所以基本上 values[] 只是指向类 "day" 中的对象的指针数组 类"日"如下所示:

class day{
public:
int year = 0;
int month = 0;
int day = 0;
string open;
string high;
string low;
string close;
string volume;
string adj;
};

在函数 findplace() 中,我厌倦了在数组中插入新的一天,以便数组按日期排序,并始终保留最新的日子,并在插入新日期时丢弃最旧的日子。它看起来像这样:

int stock::findplace(int year, int month, int day){
int j = 29;
for(j; values[j].year > year; j--){
}
for(j; values[j].month > month; j--){
}
for(j; values[j].day > day; j--){
}
if(!(values[j].year == year && values[j].month == month && values[j].day == day)){
delete &values[0];
for(int i = 0; i < j; i++){
values[i] = values[i+1];
}
}
return j;

}

尝试打印年/年月/月/月日/d的值。 我假设您以某种方式从输入文件中错误地读取了这些值,并且正在生成值数组的越界索引。

相关内容

最新更新