我见过的大多数IDE(NetBeans,QtCreator,XCode,CodeBlocks,Eclipse)提供了一种开箱即用的方法,可以在其嵌入式窗口或外部控制台之一或日志中查看标准输出但是Visual Studio.
我真的不想按照这个问题的建议分配一个单独的控制台.我也不想将它重定向到文件,因为在这个问题上建议(输出文件不是用建议的控制台命令(2>output.txt)创建的).请不要 像使用那样给出修改代码库的答案OutputDebugString.
如果以这种方式在VS内部显示标准输出是不可能的,那么其他两个备选方案的工作解决方案仍然会受到欢迎,即使用外部控制台(我尝试使用它而不看其中的输出)或日志文件.
在尝试boost::any通过boost::any_cast引用转换检索实例后,我无法保持常量正确性。
我的代码:
MyMap paramMapToSet;
MyMap& paramMap = ¶mMapToSet;
const MyMap& constParamMap = ¶mMapToSet;
A hoe;
paramMap.set(hoe, "structA");
// this works
A& hoeRef = paramMap.getByRef<A>("structA");
hoeRef.myInt = 101;
cout << paramMap.get<A>("structA").myInt << endl; // prints 101
// as well as this:
hoe = constParamMap.get<A>("structA");
cout << hoe.myInt << endl;
// and this:
const A& constHoeRef = paramMap.getByRef<A>("structA");
cout << constHoeRef.myInt << endl;
// however this doesn't work, why?? (error message below)
const A& constHoeRef = constParamMap.getByRef<A>("structA");
cout …Run Code Online (Sandbox Code Playgroud)