如何在 MFC c++ Visual Studio 中跟踪或追踪数组的元素 [英] How to keep track or trace the elements of array in MFC c++ visual studio
问题描述
我对视觉工作室/窗口应用程序还很陌生,所以我不习惯没有命令行.
基本上我有一个 CString m_storeEx = "12 + 2 - 4 "
,所以我使用 tokenize 方法将每个数字和运算符放入一个数组中:
CStringArray arr;CString resToken= m_StoreEx.Tokenize(_T(" "),curPos);while (resToken != _T("")){arr.Add(resToken);resToken = m_StoreEx.Tokenize(_T(" "), curPos);}
我希望最终结果是这样的数组 arr = ['12', '+', '2', '-', '4']
我只想检查我是否正确添加了元素.通常,如果我使用具有命令行的内容进行编码,我只会创建一个 for 循环,然后打印出数组进行检查.但是我知道在 MFC 视觉基础中这样做,因为没有命令行.我尝试使用调试工具检查数组的值,但它给了我奇怪的数字和字母.
正如
I'm fairly new to visual studios/window aplications, so im not used to not having a command line.
Basically I have for example a CString m_storeEx = "12 + 2 - 4 "
and so I used tokenize method to put each number and operator into an array by doing this:
CStringArray arr;
CString resToken= m_StoreEx.Tokenize(_T(" "),curPos);
while (resToken != _T(""))
{
arr.Add(resToken);
resToken = m_StoreEx.Tokenize(_T(" "), curPos);
}
I want the end result to be an array like this arr = ['12', '+', '2', '-', '4']
I just want to check if im adding the elements in right. Usually if I code with something that has a commandline, I'd just make a for loop, and print the array out to check. But I'd know to do that in MFC visual basics since there is no command line. I tried using the debugging tool to check the value of the array, but it just gave me weird numbers and letters.
As pointed out by l33t in his/her answer, Visual Studio has provisions to extend and customize the visualization of objects in the debugger. Details are available under Create custom views of native objects. By default, Visual Studio doesn't ship a CStringArray
visualizer, so you are left with writing your own.
The following is a simple visualizer, that displays both the collection size as well as its contents:
<?xml version="1.0" encoding="utf-8"?>
<AutoVisualizer xmlns="http://schemas.microsoft.com/vstudio/debugger/natvis/2010">
<Type Name="CStringArray">
<DisplayString>{{size={m_nSize}}}</DisplayString>
<Expand>
<ArrayItems>
<Size>m_nSize</Size>
<ValuePointer>m_pData</ValuePointer>
</ArrayItems>
</Expand>
</Type>
</AutoVisualizer>
There are several ways to enable this visualizer. The easiest deployment is to copy the XML code above to a file (e.g. CStringArray.natvis) and copy that file to the directory %USERPROFILE%\My Documents\Visual Studio 2012\Visualizers\
. Other alternatives are documented in the link above.
Once deployed, stepping through the following code
CStringArray str;
str.Add( _T( "12" ) );
str.Add( _T( "+" ) );
str.Add( _T( "2" ) );
str.Add( _T( "-" ) );
str.Add( _T( "4" ) );
produces this visualization in the debugger:
这篇关于如何在 MFC c++ Visual Studio 中跟踪或追踪数组的元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!