我一直在試圖在Visual Studio 2010中創建一個示例應用程序。我沒有得到什麼問題,因爲代碼是完美編譯的,但是提供了運行時錯誤。這裏是代碼:在Visual Studio 2010中映射的運行時錯誤x64
#include <Map>
#include <string>
#include <sstream>
#include <iostream>
#include <fstream>
using namespace std;
int main(int argc, char* argv[])
{
map <int, string> *sss = new map<int, string>;
sss->at(0) = "Jan";
sss->at(1) = "Feb";
sss->at(2) = "Mar";
sss->at(3) = "Apr";
sss->at(4) = "May";
sss->at(5) = "Jun";
string current = NULL;
ofstream myfile;
myfile.open("daily_work.txt");
myfile << "***** DAILY WORK *****" << endl;
for(int i = 0; i < 6; i++)
{
string month = sss->at(i);
for(int j = 1; j < 31; j++)
{
stringstream ss;
ss << j;
current = ss.str();
current.append(" ");
current.append(month);
current.append(" = ");
myfile << current << endl;
}
current = "";
}
printf("Completed!");
myfile.close();
sss->clear();
delete sss;
sss = NULL;
return 0;
}
錯誤在第2行被拋出。
sss->at(0) = "Jan";
請在這裏找到錯誤:
at()拋出元素是否存在,是否正確?編輯:看jrok的評論 – dans3itz