许多其他问题的答案告诉您,您可以使用类似于以下代码的代码捕获流程的输出:
void UnsortedType::SplitLists(UnsortedType list,
ItemType item,
UnsortedType& list1,
UnsortedType& list2){
ItemType whichItem;
int numItems = list.GetLength();
//Loop through all items in the list
for(int i = 0; i < numItems; i ++){
whichItem = list.GetNextItem();
try{
switch(whichItem.ComparedTo(item)){
case LESS:
case EQUAL:
if(list1->isFull()){//Error thrown on this line
throw std::string("List1 is full.");
return;
}
//add item to list1
list1->PutItem(whichItem);//Error thrown on this line
break;
case GREATER:
if(list2->isFull()){//Error thrown on this line
throw std::string("List2 is full.");
return;
}
//add item to list2
list2->PutItem(whichItem);//Error thrown on this line
break;
}
}
catch(std::string e){
std::cout << e << std::endl;
}
}
};
有许多变体或多或少实现相同的功能,但是它们都重定向标准输出/错误-有没有一种方法可以捕获它们,同时仍将它们显示在cmd窗口中?