Jump to content


aaabbbcccddd's Content

There have been 1 items by aaabbbcccddd (Search limited from Wed, 27 Sep 23)


By content type

See this member's

Sort by                Order  

#11740 cin i scanf

Posted by aaabbbcccddd on 24 February 2010 - 17:08 in Programowanie

Wiem, że to być może na poziomie przedszkola...

Załóżmy, że chcę w C++ napisać program sumujący dowolną, niepodaną wcześniej ilość liczb. Oto, co mi przychodzi do głowy:

#include
#include
using namespace std;

main()
{ int a, s;
s=0;
while(scanf("%d", &a)!=EOF) s = s + a;
cout << s;
return 0;
}


Pytanie jest takie: czy mogę jako warunek pętli while użyć cin zamiast scanf? I jak to zrobić?