크기을 vector
으로 인쇄하려고합니다. 쉽게 들리지만 벡터는 map
입니다. 나는이 같은 크기를 표시하려고
map<string, vector<map<vector<string> , vector<string> > > >::iterator it;
반복자를 통한 벡터의 인쇄 크기
: 현재 나는이처럼 보이는지도에 반복자를
편집 :
반복자는 다음과 같이 intialised한다 : it = csvMap.find(commandList.at(lineCount));
cout<<"Size of vector in Map after modifying: " << it->second.size() <<"\n"<<endl;
작동하지 않는 경우 프로그램이 다운됩니다. 나는 임시 벡터을 만들고 그 값을 it->second;
으로 채우는 것이 좋다고 생각한다. 그러나 크기를 얻는 것은 단지 공간을 낭비하는 것이 아닌가?
이렇게하는 더 좋은 방법이 있습니까?
미리 감사드립니다.
EDIT2 :가 제거 된 코드
편집 3 : 새로운 코드 :
map<vector<string> , vector<string> > parameterMap;
parameterMap.insert(pair<vector<string> , vector<string> > (
part1_input, part2_output));
map<string, vector<map<vector<string> , vector<string> > > >::iterator it;
cout<<"\nSize of CSV Map before modifying: " << csvMap.size() <<endl;
//cout<<"Size of vector in CSV Map before modifying: " << it->second.size() <<"\n"<<endl;
if(csvMap.size() == 0)
{
/*
* csvMap is empty -> no need to search for something. Just insert the fist entries
*/
listedParameterMap.insert(listedParameterMap.end(), 1, parameterMap);
csvMap.insert(pair<string, vector<map<vector<string> ,
vector<string> > > > (commandList[lineCount],
listedParameterMap));
cout<<"CSV Map size: " << csvMap.size() <<endl;
}
else
{
/*
* Search if the Command is already available, if not,
* add it to the map with its corresponding list of maps (in/output values)
* find returns map::end if key is not found
*/
cout<<"Checking if: " << commandList.at(lineCount) << " is already in the list \n" << endl;
it = csvMap.find(commandList.at(lineCount));
if (it == csvMap.end())
{
/*
* it = csvMap.end() is true
* The command isn't found
*/
cout<< commandList.at(lineCount) << " command not available. Inserting it! \n" << endl;
listedParameterMap.insert(listedParameterMap.end(), 1, parameterMap);
csvMap.insert(pair<string, vector<map<vector<string> ,
vector<string> > > > (commandList[lineCount],
listedParameterMap));
}
else
{
/*
* it != csvMap.end()
* The command is found. Append the parameterMap to the vector in the map
*/
cout<< commandList.at(lineCount) << " is already in the list! Appending parameters on pos: "<< it->second.size()-1<< "\n" << endl;
it->second.push_back(parameterMap);
}
}
cout<<"\nSize of CSV Map after modifying: " << csvMap.size() <<endl;
cout<<"Size of vector in CSV Map after modifying: " << it->second.size() <<"\n"<<endl;
나는 사람이 여전히이 읽고 희망을 ...
이제는 it.second
이 첫 번째 간섭에서 문제가되는 것으로 확인되었습니다. 그러나 나는 이유를 알지 못합니다. (또한 위의 코드에서)
코드 :
if(csvMap.size() == 0)
{
/*
* csvMap is empty -> no need to search for something. Just insert the fist entries
*/
listedParameterMap.insert(listedParameterMap.end(), 1, parameterMap);
csvMap.insert(pair<string, vector<map<vector<string> ,
vector<string> > > > (commandList[lineCount],
listedParameterMap));
cout<<"CSV Map size: " << csvMap.size() <<endl;
cout<<"listedParameterMap: " << listedParameterMap.size() <<endl;
cout<< commandList.at(lineCount) << " is already in the list! Appending parameters on pos: "<< it->second.size()<< "\n" << endl;
}
이 보인다되지 작동합니다. 그것으로 그것의가는 것이 있더라도. 왜 그런가? comanndList 및 listedParameterMap은 내가 확인한 것입니다.
반복 루프를 게시하십시오. 우리는 맥락이 필요합니다. –
'it-> second.size()'를 사용하기 전에'if (it! = csvMap.end())'를 체크하고 있는가? – Naveen
검색중인'lineCount'가 존재합니까? 검색 후'map :: end'와 평등을 확인합니까? –