使用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();
}
}

最新更新