可以在for循环中使用跟踪语句吗?
Will it be possible to use trace statement in for loop?
我需要在for循环的每个语句中打印一些东西。因为程序在for循环中崩溃了。所以我尝试在for循环中添加跟踪语句
for ( ICollection::const_iterator iter = pCol->begin(NULL),OutputDebugString(L"One"); iter != pCol->end(NULL); ++iter)
{ //see OutputDebugString
我得到以下错误,
Error 1 Error C2664:"IIteratable: ConstIterator:: ConstIterator (std:: auto_ptr<_Ty>)":无法将参数1从'const wchar_t[4]'转换为'std::auto_ptr<_Ty>' filename.cpp 629
现在我在样本应用程序中尝试了同样的事情,它工作得很好,
void justPrint(std::string s)
{
cout<<"Just print";
}
int main()
{
int i;
for(i = 0,justPrint("a"); i<3; i++)
{
}
return 0;
}
OutputDebugString和justPrint都返回void,我在我的代码中做错了什么
错误是您将OutputDebugString
的返回值分配给iter
。尝试交换顺序,因为逗号操作符(,
)给出的最后一个值,在这种情况下,是OutputDebugString
的返回值。
for ( ICollection::const_iterator iter = (OutputDebugString(L"One"), pCol->begin(NULL)); iter != pCol->end(NULL); ++iter)
{ //see OutputDebugString
但是为什么需要OutputDebugString
呢?您可以在for循环之前添加它,以避免混淆。
如果需要在pCol->end(NULL)
之后打印调试字符串,可以使用辅助函数。
static ICollection::const_iterator begin_helper(SomeType &pCol) {
auto iter = pCol->begin(NULL);
OutputDebugString(L"One")
return iter;
}
for ( ICollection::const_iterator iter = begin_helper(pCol); iter != pCol->end(NULL); ++iter)
{ //see OutputDebugString
相关文章:
- 我的简单if-else语句是如何无法访问的代码
- 有一个打印语句的函数是一种糟糕的编程实践吗
- 线程,如果else语句,都是错误的上下文切换后,会发生什么
- 为什么是0;C++中的有效语句
- Insert函数不适用于2 if语句C++
- If语句未被求值C++
- C++嵌套if语句,基本货币交换
- 多个If语句与使用逻辑运算符计算条件的单个语句的比较
- 光线跟踪器灯光反射错误
- 是否可以使用if constexpr删除控制流语句
- 无法理解此 return 语句的功能,没有它就会发生运行时错误
- 我似乎对if/else的基本语句有问题:/
- 当调用switch语句中的函数时(即使函数不包含循环),似乎是永不结束的循环的问题
- 人脸跟踪arduino代码的优化
- If语句在c++中被忽略
- 比较if语句中的数组值和int值
- 以在Qt中的IF语句中设置时间延迟
- 跟踪滚动条上的鼠标事件
- Craps游戏问题,忽略if语句
- 可以在for循环中使用跟踪语句吗?