我想创建一个文件对的映射...首先,我正在使用FindFirstFile和FindNextFile搜索文件的指定目录,当找到文件时,我搜索地图看看相关的文件是否在那里。如果其他文件已添加到地图中,则新找到的文件将插入先前找到的文件旁边。如果找不到相关文件,则新文件将被插入到地图中,并且其对保持不变。动态插入字符串到std :: map
解释得: 让我们说我们有2个文件file.1.a和file.1的 这些文件表示一对,因此应该被添加到地图作为一对
//map<File w/o .a, File w .a>
std::map<CString, CString> g_map;
int EnumerateFiles(LPCTSTR Dir)
{
//Search Files....
//Found a File....(for ex: file.1)
//Append .a to the string and search for it in the map
BOOL bAdded = FALSE;
for(std::map<CString, CString>::iterator itr = g_map.begin(); itr != g_map.end(); itr++)
{
if(StrCmp(tchAssocFile, itr->second) == 0)
{
bAdded = TRUE;
//pair the string with the other one;
}
}
if(!bAdded)
//Add the new string to the map and leave its associate blank
//Do the same in reverse if the associate was found first....
}
希望这是清楚的,因为我想不出有什么其他的方式来表达它......斯里。
能否请您在解决这个问题上需要帮助...
问候
你实际上没有告诉我们问题是什么。 – 2009-12-21 15:15:32
嗯,就像我说过的,我不知道该如何放置它,但我们假设我想填充一张地图,因为我需要一个字符串对的实际需求......例如,如果我找到一个文件,我会检查是否已将其关联关系添加到地图中,如果是,则将该文件与其关联关联。如果不是,则将该文件添加到新的[行]中,并等待找到关联者并将它们配对。 – 2009-12-21 15:22:03