[英]Run C++ in Sublime Text 3 on Mac OSX
我知道有一個內置的 C++ 編譯器和 ST3 的運行插件。 這很好地構建了我的程序。 運行代碼,它運行控制台中的第一部分,但在第一個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;
}
如果有人知道為什么它只運行了一半,並且可以幫助我弄清楚,那就太棒了。 謝謝!
我猜想這個問題的出現不是因為你用 sublime 編譯,而是你試圖從 sublime 內部運行應用程序,因為它不能很好地處理交互式程序。
如果你從 sublime 編譯你的應用程序並從控制台運行它,一切都應該正常工作。
您可以使用此答案中指定的技巧在外部 cmd 終端中運行應用程序。
在 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}'"]
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.