我有一個std ::地圖是這樣的:std :: map值是空的,即使我分配了一個值?
std::map<std::string, std::string> imagePaths;
在我的代碼後來我給它一個值,就像這樣:
imagePaths.insert(std::make_pair("Square.bmp", "Square"));
然而,當我環槽地圖,顯示兩個這樣的第一和第二值:
for (auto iterator = imagePaths.begin(); iterator != imagePaths.end(); iterator++)
{
std::cout << "Loaded > " << imagePaths[iterator->first] << " image path : " << imagePaths[iterator->second] << std::endl;
}
我得到的輸出:
加載>方形圖像路徑:
而其餘的是,由於某種原因,空的,即使我給它的"Square.bmp"
值。
無法弄清楚我做錯了什麼。 :/
這是可行的,但如果我想打印出「Square」的值呢?我試過這個:'std :: cout << imagePaths [「Square」] << std :: endl;'這不起作用。 – BiiX
很酷。你可能想把它標記爲答案:) –
我會在2分鐘內,必須等待一會才接受。 :P – BiiX