我有这个代码,我写的是为了计算Twitter上两个用户之间的分离程度。我在第三次for循环的第二次迭代中发生了错误。当它到达IdList.push_back(myIDs2["ids"][l].GetInt());
当它到达这一点时,它以代码0x3退出程序。我是否正确地假设我正在阅读并通过我的向量进行交互导致内存问题?
这是代码
std::vector<std::vector<std::string>> separationStages(6);
std::vector<int> IdList;
std::vector<std::string> stringIdList;
std::string response;
std::string nextCursor = "";
std::string previousCursor = "";
int degreesOfSeparation = 0;
//request my ids
twitterobj.friendsIdsGet(nextCursor, myScreenName, false);
twitterobj.getLastWebResponse(response);
//if the response doesnt contain an error
if (!errorCheck(response))
{
std::cout << "There has been an error. " <<response << std::endl;
}
else
{
Document myIDs;
myIDs.Parse(response.c_str());
myIDs.IsObject();
myIDs.HasMember("ids");
myIDs["ids"].IsArray();
//for how many ids in the response set each of those into separation vector
for (size_t i = 0; i < myIDs["ids"].Size(); i++)
{
std::string temp = "";
myIDs["ids"][i].IsInt();
IdList.push_back(myIDs["ids"][i].GetInt());
temp = std::to_string(IdList[i]);
separationStages[0].push_back(temp);
}
IdList.clear();
//checking how many ids in first degree
std::cout << separationStages[0].size() << std::endl;
for (size_t j = 0; j < separationStages[0].size(); j++)
{
if (separationStages[0][j] == degreeSearch)
{
degreesOfSeparation = 1;
return degreesOfSeparation;
}
}
for (size_t k = 0; k < separationStages[0].size(); k++)
{
std::cout << "Checking friend number " << k + 1 << " in first degree" << std::endl;
Sleep(60000);
//get that users friend list
twitterobj.friendsIdsGet(nextCursor, separationStages[0][k], true);
twitterobj.getLastWebResponse(response);
if (!errorCheck(response))
{
std::cout << "error at start of second degree" << std::endl;
}
else
{
Document myIDs2;
myIDs2.Parse(response.c_str());
myIDs2.IsObject();
myIDs2.HasMember("ids");
myIDs2["ids"].IsArray();
for (size_t l = 0; l < myIDs2["ids"].Size(); l++)
{
std::string temp = "";
myIDs2["ids"][l].IsInt();
IdList.push_back(myIDs2["ids"][l].GetInt());
temp = std::to_string(IdList[l]);
separationStages[1].push_back(temp);
}
IdList.clear();
std::cout << "Size of separationStages[1] = " << separationStages[1].size() << std::endl;
for (size_t m = 0; m < separationStages[1].size(); m++)
{
if (separationStages[1][m] == degreeSearch)
{
degreesOfSeparation = 2;
return degreesOfSeparation;
}
}
}
}
}
return degreesOfSeparation;