Im still quite new in programming c++ - so please forgive me if my code is not perfect yet (still im open to any suggestions to improve ;) )
I have a problem running this code (only part of larger project).
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;}
Project compiles fine but as the function "import" is called my programm crashes immediately. The debugger gives me back the error "cannot find bound of current function" at this part of the code:
{
getline(input, open, ',');
values[index].open = open;
}
the strange thing is, that if I delete this part of the code:
{
getline(input, year, '-');
y = atoi(year.c_str());
}
a few lines obove the critical section my programm works fine (meaning it doesn't crash but of course doesn't do what it is supposed to do).
I'm currently unsing CodeBlocks as an IDE.
Can anyone help me with this? I am really desperate by now as I already tried out everything I know...
As suggested here is more information about values and 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);
};
so basically values[] is just an array of pointers to objects from class "day" class "day" looks like this:
class day{
public:
int year = 0;
int month = 0;
int day = 0;
string open;
string high;
string low;
string close;
string volume;
string adj;
};
and in function findplace() I tired to insert a new day into the array, so that the array is sorted by date and always keeps the newest days and discards the oldest when inserting a new one. It looks like this:
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;
}