|
查看: 1263|回复: 4
|
C++ system("pause") [已解答] 多謝多謝!
[复制链接]
|
|
|
小弟是C++初學者,對C++知識幾乎是0...
剛開始學就發現問題了...
就是我build好我的project后,debug時那個dos畫面一閃即逝......那是正常的嗎?
我用的是Microsoft Visual C++ express 2008
例如我剛開始學到的...
#include <iostream>
using namespace std;
int main()
{
cout << "Hello\n";
return 0;
}
當我run時,那畫面停留不到1秒就消失了.....
之後我在網上找到方法在return前加一句system("pause" 就能把畫面停留著。
可是我在教學中或者見過的code都沒見過需要用這指令的......是不是有什麽setting我沒做到?
*********************************************************************************************************************
問題2.
在其中一個exercises問題里問到
Write a program that reads in five integers and determines and prints the largest and the smallet integers in the group. Use only the programming techniques you learnd in this chapter.
在這個chapter里只學到cin, cout, 加減乘除, relational operator, 還有if statement而已......連else if都還沒學到....
試了很久都弄不到....
if (input1 < input2 , input3 , input4 , input5)
cout << "Smallest is " << input1 << endl;
if (input2 < input1 , input3 , input4 , input5)
cout << "Smallest is " << input2 << endl;
if (input3 < input1 , input2 , input4 , input5)
cout << "Smallest is " << input3 << endl;
..
..
..
自己試驗的.....結果是....全部cout都print出來了..........
哪位前輩可以指教下...
[ 本帖最后由 lastufo 于 7-8-2008 07:12 PM 编辑 ] |
|
|
|
|
|
|
|
|
|
|
发表于 7-8-2008 05:24 PM
|
显示全部楼层
回复 1# lastufo 的帖子
你的if statement裡面的expression寫錯了
input1 < input2 , input3 , input4 , input5
這樣子是不行的
用&&
這個是logical And operation
有學過boolean algebra的話應該不難明白
所以你可以像這樣寫
input1 < input2 && input1 < input3 && input1 < input4 && input1 < input5
懂了嗎? |
|
|
|
|
|
|
|
|
|
|

楼主 |
发表于 7-8-2008 06:14 PM
|
显示全部楼层
回复 2# Squall_Chua 的帖子
我試過用&.........原來是&&哦.......
謝了
不過除了我用這個方法還有其他code可以做到同樣效果嗎? |
|
|
|
|
|
|
|
|
|
|
发表于 7-8-2008 06:57 PM
|
显示全部楼层
問題1
用ctrl+f5來compile
 |
|
|
|
|
|
|
|
|
|
|

楼主 |
发表于 7-8-2008 07:11 PM
|
显示全部楼层
原帖由 cheng1986 于 7-8-2008 06:57 PM 发表 
問題1
用ctrl+f5來compile
原來如此!
多謝你的解答...真的差點抓爆頭....! |
|
|
|
|
|
|
|
|
| |
本周最热论坛帖子
|