使用Qt Creator在调试模式下编译一段代码
Compile a piece of code in debug mode with Qt Creator
我正在向你展示我的问题。 我正在Qt Creator中为一个大学项目创建一个应用程序。 正如您在下面的代码中看到的,我在方法中插入了两个"cout",因为它们对我检查程序是否有效很有用,这意味着它们没有实际功能。 查看后,教授委派我在调试模式下使用 #IFDEF 进行操作,以便包含"cout"的代码部分仅对程序员可见,而对假设的客户端不可见。 我希望我已经很好地解释了我的问题,我感谢任何可以帮助我的人。 考虑到在这种事情上我是新手。 谢谢
您必须使用预处理器宏。qt创建者的正确版本是QT_DEBUG
。您的代码应如下所示:
void BankAccount::addTransaction(Transaction* t){
if(t->getType()==0 && actualAccountBalance < t->getTransactionValue()) {
#ifdef QT_DEBUG
cout<<"Unable to add transaction: insufficient balance to make the requested withdrawal!"<<endl;
#endif
; // empty command, because of empty if
}
else if(find(transactions.begin(),transactions.end(),t) != transactions.end()) {
#ifdef QT_DEBUG
cout<<"This transaction has already been added!"<<endl;
#endif
; // empty command, because of empty if
}
else{
transactions.push_back(t);
assignID(t);
actualAccountBalance = calculateAccountBalance();
}
}
相关文章:
- 如何为一段代码启用 -permissive
- 使用Qt Creator在调试模式下编译一段代码
- 无法理解一段具有完美转发和省略号的C++代码
- 防止一段代码在协程中并发执行
- 通过创建单个线程来运行一段代码可加快执行速度
- (C++)比较两段代码,一段有效,一段无效,无法找出区别
- 有没有一种标准方法来确保一段代码在全局范围内执行
- C++函数 Sleep() 在一段代码之前执行
- C++中的继承和模板:为什么以下一段代码不编译?
- 一段C++代码出现错误"invalid pointer"
- 我必须编写一段代码,基本上执行c++中的strlen()函数,哪里出了问题
- 关于行列式计算的一段代码的问题
- 将两个或多个互斥体应用于一段代码
- 我应该如何处理编写一段确定订阅包节省的代码的逻辑
- 使类使用浮点数和整数(分析一段代码)
- 如何在C++中编写一段代码以查找系统路径上文件的完整路径
- 有关一段带有模板、转换运算符和复制 ctor 的代码的问题
- 从第二次调用开始在函数中执行一段代码
- 将一段C++代码封装到Python中
- 解释一段c++代码