You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在C++中将list存储到map中?附Xcode调试问题澄清

问题澄清: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

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.26 10:51:12