C ++没有在Xcode控制台中显示cout,但在终端中运行完美

时间:2017-04-01 15:46:06

标签: c++ xcode debugging cout

基本上我在[JsonObject] public partial class EquipmentItems : List<EquipmentItem> { } [JsonObject] public partial class EquipmentItem : IItemData { #region Private fields private string equipmentIDField; private string catIDField; private string classIDField; private string lineSequenceField; private string quantityField; private string toolFlexField; private string hourlyRateField; private string dailyRateField; private string weeklyRateField; private string monthlyRateField; private string minRateField; private bool daysOverField; private bool weeksOverField; private bool monthsOverField; #endregion #region Public properties /// <remarks/> public string Equipment { get { return this.equipmentIDField; } set { this.equipmentIDField = value; } } /// <remarks/> public string CatID { get { return this.catIDField; } set { this.catIDField = value; } } /// <remarks/> public string ClassID { get { return this.classIDField; } set { this.classIDField = value; } } /// <remarks/> public string LineSeq { get { return this.lineSequenceField; } set { this.lineSequenceField = value; } } /// <remarks/> public string Quantity { get { return this.quantityField; } set { this.quantityField = value; } } /// <remarks/> public string ToolFlex { get { return this.toolFlexField; } set { this.toolFlexField = value; } } /// <remarks/> public string HrRate { get { return this.hourlyRateField; } set { this.hourlyRateField = value; } } /// <remarks/> public string DayRate { get { return this.dailyRateField; } set { this.dailyRateField = value; } } /// <remarks/> public string WkRate { get { return this.weeklyRateField; } set { this.weeklyRateField = value; } } public string MinRate { get { return this.minRateField; } set { this.minRateField = value; } } /// <remarks/> public string MoRate { get { return this.monthlyRateField; } set { this.monthlyRateField = value; } } /// <remarks/> public bool DayOver { get { return this.daysOverField; } set { this.daysOverField = value; } } /// <remarks/> public bool WkOver { get { return this.weeksOverField; } set { this.weeksOverField = value; } } /// <remarks/> public bool MoOver { get { return this.monthsOverField; } set { this.monthsOverField = value; } } #endregion }

中运行一个简单的程序
Xcode Version 8.3 (8E162)

我看到有关#include <iostream> using namespace std; int main() { int a; cout << "What is your age: "; cin >> a; cout << "My age is " << a << endl; return 0; } 需要刷新以及所有std::cout won't printXcode debugger not showing C++ cout output的不同问题。在我放置cout之前,Xcode调试器不会打印cout。但是,它在终端上运行得非常好。

如果我必须在单行中使用\n or endl和用户输入年龄而不是放置What is your age:的下一行,该怎么办?

这是Xcode调试器在构建和运行后显示的内容

This is what the Xcode debugger shows after build and run

这是用户输入并显示结果

This is when user inputs and displays the result

这是在终端上,这正是我需要Xcode调试器上的输出。

This is on the terminal

2 个答案:

答案 0 :(得分:2)

通过一些研究,cin and cout上发布的Xcode Version 8.3 Build 8E162上的Mar 27, 2017流似乎存在错误。 降级为Xcode Version 8.2.1就像魅力一样。

答案 1 :(得分:0)

您已经自己解决了问题:zip=4000使用缓冲输出,应该始终刷新。您可以使用std::cout,使用std::cout << "What is your age? << std::flush或添加隐式刷新的std::cout.flush()换行符来实现此目的。

完整的解决方案可能如下所示:

std::endl