int main(){
//Date Variables
int day;
int month;
int year;
string comName;
string temp;
string temp2;
//Time Variables
int hours;
int minutes;
int seconds;
string amPm;
ofstream ofstr("output.csv");
float price = 0.00;
int volume;
float value = 0.00;
float runningVol = 0.00;
float runningVal = 0.00;
float runningPrice = 0.00;
string condition;
string fileName;
string tempCName;
string compDate;
ifstream inFile;
ifstream compFile;
ifstream mainFile;
map<string, Vector <Share>> stlMap;
inFile.open("code_index.txt");
if(inFile.is_open()){
while(!inFile.eof()){
getline(inFile,tempCName);
cout << "read next line in code_index" << endl;
comName = tempCName+"\\sales_index.txt";
cout << "Company name to open is: " << comName << endl;
compFile.open(comName);
if(compFile.is_open()){
while(!compFile.eof()){
getline(compFile,fileName);
cout << "Read the fileName: " << fileName << endl;
fileName = tempCName+"\\"+fileName;
mainFile.open(fileName);
if(mainFile.is_open()){
Vector <Share> myVec;
while(!mainFile.eof()){
compDate = "";
cout << "Stored all the variables" << endl;
//Getting and storing the Date
getline(mainFile,temp2,'/');
day = atoi(temp2.c_str());
getline(mainFile,temp2,'/');
month = atoi(temp2.c_str());
getline(mainFile,temp2,' ');
year = atoi(temp2.c_str());
//cout << "date = " << day << "mo = " << month << "yr = " << year;
//Date d;
Date d(day,month,year); //Sending them to the Date class using the parameterized constructor
compDate = tempCName + "_" + d.returnDate();
//cout << "Date is: "<< compDate << endl;
cout << compDate << endl;
// Getting and storing the time variable
getline(mainFile,temp2,':');
hours = atoi(temp2.c_str());
getline(mainFile,temp2,':');
minutes = atoi(temp2.c_str());
getline(mainFile,temp2, ' ');
seconds = atoi(temp2.c_str());
getline(mainFile,temp2,',');
amPm = temp2;
//Time t;
Time t(hours,minutes,seconds,amPm);
//cout << "Hours = " << hours << "minutes = " << minutes << "seconds = " << seconds << " " << amPm;
getline(mainFile,temp2,',');
price = atof(temp2.c_str());
//cout << price;
getline(mainFile,temp2,',');
volume = atoi(temp2.c_str());
getline(mainFile,temp2,',');
value = atof(temp2.c_str());
getline(mainFile,temp2,'\n');
condition = temp2;
Share s(price,volume,value,d,t);
myVec.push_back(s);
}
stlMap[compDate] = myVec;
mainFile.close();
}
else{ cout << "Specified day file not found";}
}
compFile.close();
}
else{cout << "Specified company folder not found / sales_indexfile not found" << endl;}
}
inFile.close();
}
else
{cout << "code_index.txt not found. Please make sure the file exists";}
for(map<string, Vector <Share>>::iterator itr = stlMap.begin();itr!=stlMap.end() ;itr++ )
{
cout << "map values\n";
//cout << itr->first << endl;
//cout << itr->second.length() << endl;
}
int iii = 0;
cin >> iii;
return 0;
}
我有自己的模板化矢量,但这个for循环从地图打印会导致断言错误,请帮忙吗?
另外,如果我注释掉我进入地图的位,错误就消失了。 这让我说,矢量不是问题的原因。