![](/img/trans.png)
[英]How can I make the program I wrote with QT4 execute when I launch it not from IDE?
[英]How can I make sure the program stops running after the IDE has output result
我是C ++的新手。 我以前在NetBeans中運行過代碼。 但是,在輸入字符串並且IDE輸出結果之后,我期望程序停止運行。
但是,NetBeans IDE底部有一個指示程序仍在運行的欄。
為什么會這樣呢?
我應該對代碼進行哪些更改,以便程序停止運行?
#include <iostream>
#include <string>
using namespace std;
int main() {
cout << "Enter a string of characters including punctuation." << endl;
for (string s; getline(cin, s); cout << endl)
for (auto i : s)
if (!ispunct(i)) cout << i;
return 0;
}
程序循環返回到getline,如您在for語句中所述。 您的退出條件是getline返回false。 為此,您需要關閉文件,方法是在Unix上輸入Control-D或在Windows上輸入Control-Z 。
另一種策略是循環直到有人鍵入“ q”或“ exit”或空行。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.