【问题标题】:Run C++ in Sublime Text 3 on Mac OSX在 Mac OSX 上的 Sublime Text 3 中运行 C++
【发布时间】:2018-03-22 10:52:00
【问题描述】:

我知道 ST3 有一个内置的 C++ 编译器和运行插件。这可以很好地构建我的程序。运行代码,它在其控制台中运行第一部分,但在第一个 cin >> 处停止。当我直接从终端运行在 ST3 中编译的文件时,代码运行良好。

源码:

#include <iostream>
using namespace std;

int main()
{
   int begInv;
   int sold;
   int store1, store2, store3;

   // Get the beginning inventory for all the stores.
   cout << "One week ago, 3 new widget stores opened \n";
   cout << "at the same time with the same beginning \n";
   cout << "inventory. What was the beginning inventory?";
   cin >> begInv;

   // Set each store's inventory.
   store1 = begInv;
   store2 = begInv;
   store3 = begInv;

   // Get the number of widgets sold at store 1.
   cout << "How many widgets has store 1 sold? ";
   cin >> sold;
   store1 -= sold; // Adjust store 1's inventory.

   // Get the number of widgets sold at store 2.
   cout << "How many widgets has store 2 sold? ";
   cin >> sold;
   store2 -= sold; // Adjust store 2's inventory.

   // Get the number of widgets sold at store 3.
   cout << "How many widgets has store 3 sold? ";
   cin >> sold;
   store3 -= sold; // Adjust store 3's inventory.

   // Display each store's current inventory.
   cout << "\nThe current inventory of each store:\n";
   cout << "Store 1:"  << store1 << "\n";
   cout << "Store 2:"  << store2 << "\n";
   cout << "Store 3:"  << store3 << "\n";
   return 0;
}

Screenshot of the result in ST3.

如果有人知道为什么它只运行了一半,并且可以帮助我弄清楚,那就太棒了。谢谢!

【问题讨论】:

标签: c++ macos sublimetext3 sublimetext sublime-text-plugin


【解决方案1】:

我猜这个问题的出现不是因为你用 sublime 编译,而是你试图从 sublime 内部运行应用程序,因为它不能很好地处理交互式程序。

如果你从 sublime 编译你的应用程序并从控制台运行它,一切都应该正常工作。

您可以使用answer 中指定的技巧在外部 cmd 终端中运行应用程序。

【讨论】:

  • 好的,这绝对是问题所在。谢谢!当我回到我的笔记本电脑上时,我将测试你今晚提到的线程中的一个技巧。
【解决方案2】:

在 Mac 上试试这个:

 {
    "cmd": ["bash", "-c", "/usr/bin/g++ '${file}' -std=c++11 -o '${file_path}/${file_base_name}' && open -a Terminal.app '${file_path}/${file_base_name}'"]
 }

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-04-22
    • 2014-08-10
    • 1970-01-01
    • 1970-01-01
    • 2017-06-28
    • 1970-01-01
    • 2014-06-09
    • 2017-05-22
    相关资源
    最近更新 更多