如何在C++中将list存储到map中?附Xcode调试问题澄清
Hey there, let me clear this up right away: the issue you're seeing is not with your code—it's actually a quirk of the Xcode debugger. Your code is perfectly valid.
I get where you're coming from too—you're not new to programming, but you're just getting started with C++, so it's confusing when it looks like values from your list aren't saving after inserting them into a map.
Here's the relevant code you shared:
// main.cpp #include <iostream> #include <string> #include <memory> #include <list> #include <map> #include "Movie.h" #include "Date.h" #include "Cinema.h" using namespace std; int main() { Cinema cinema; string name = "tran..."; // (注:原代码片段截断,保留你提供的现有部分) }
Xcode's debugger can sometimes show misleading representations of container contents, especially when dealing with STL containers like map and list alongside custom classes like Cinema, Movie, etc. If you add simple print statements to output the contents of your map right after insertion, you'll likely find the values are indeed being stored correctly.
内容的提问来源于stack exchange,提问作者FoundNil

