我一直在尝试在 Visual Studio 2010 中创建一个示例应用程序。由于代码正在完美编译,我没有得到什么问题,但是给出了运行时错误。这是代码:
#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;
}
错误在 main 的第 2 行抛出。
sss->at(0) = "Jan";
请在此处查找错误: