代碼:
#include "stdafx.h"
#include"iostream"
#include
#include
#include
#include
#include
using namespace std;
typedef hash_map myMap;
void CharsAllSequen(myMap &resultMap, string &str, unsigned int n, double defaultVal);
void Clear0ForStrQuen(myMap &resultMap);
int main()
{
myMap totalMap;
myMap resultMap;
string str;
CharsAllSequen(resultMap, str, 6, 0.00323223);
stringstream ss;
for (int i = 0; i < 3000; i++)
{
myMap::iterator iter;
for (iter = resultMap.begin(); iter != resultMap.end(); ++iter)
{
string strTemp = iter->first;
ss.str("");
ss.clear();
ss << "_";
ss << i;
strTemp += ss.str();
totalMap.insert(myMap::value_type(strTemp, iter->second + i / 3001.0));
}
}
return 0;
}
void Clear0ForStrQuen(myMap &resultMap)
{
myMap::iterator iter = resultMap.begin();
while (iter!=resultMap.end())
{
iter->second = 0;
++iter;
}
}
//獲取特定長度,由0,1,2,3四個字符組成的字符串,比如010203,作為key,值設置為defaultVal
void CharsAllSequen(myMap &resultMap, string &str, unsigned int n, double defaultVal)
{
if (n==0)
{
if (str.size()>0)
{
resultMap.insert(myMap::value_type(str, defaultVal));
}
else
{
return;
}
}
else
{
for (int i = 0; i < 4; i++)
{
stringstream ss;
ss << i;
string temp = ss.str();
str.append(temp);
CharsAllSequen(resultMap, str, n - 1, defaultVal);
str = str.substr(0, str.size() - 1);
}
}
}
引發這個錯誤的原因是內存不足,在診斷工具裡看下內存吧