By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
445,778 Members | 1,997 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 445,778 IT Pros & Developers. It's quick & easy.

istream and while(cin >> i)

P: n/a
ax
to implement std::cout and file output seems simple but for file input
and cin i have some question for the "std::cin"

#include <iostream.h>

int main(void)
{int n, sum=0;
while(cin >> n) sum+=n;
cout << "somma = " << sum << endl;
return 0;
}

so if (cin >> n) is an object "istream" and it is not a pointer
how know "the while" when to stop the loop or to continue the loop?
i think something somethink of kind (cin >> n)!=(int)0

here seems that this little program has too many assembly language
translation. it seems it call a long function that has like argument
"cin" but i didn't find why all these lines

;
; while(cin >> n) sum+=n;
;
@2:
mov edx,dword ptr [ebp-4]
add dword ptr [ebp-8],edx
@3:
lea ecx,dword ptr [ebp-12]
push ecx
push offset @_STL@cin
call toolongcall
add esp,8
mov eax,dword ptr [ebp-12]
mov dword ptr [ebp-4],eax
mov edx,dword ptr [ebp-12]
mov dword ptr [ebp-16],edx
mov ecx,dword ptr [ebp-4]
cmp ecx,dword ptr [ebp-12]
je short @4
mov eax,dword ptr [ebp-16]
cmp eax,dword ptr [ebp-12]
je short @4
mov ebx,dword ptr [@_STL@cin]
mov esi,dword ptr [ebx+8]
or esi,4
cmp dword ptr [ebx+108],0
je short @6
mov eax,esi
jmp short @7
@6:
mov eax,esi
or eax,1
@7:
mov dword ptr [ebp-20],eax
mov edx,dword ptr [ebp-20]
mov dword ptr [ebx+8],edx
mov ecx,dword ptr [ebx+8]
and ecx,dword ptr [ebx+20]
je short @5
push ebx
call @@_STL@ios_base@_M_throw_failure$qv
pop ecx
@4:
@5:
mov eax,offset @_STL@cin
mov edi,dword ptr [eax]
test byte ptr [edi+8],5
je short @11
xor edi,edi
@11:
test edi,edi
jne short @2
Thank you
Jun 30 '06 #1
Share this Question
Share on Google+
3 Replies


P: n/a
TB
ax skrev:
to implement std::cout and file output seems simple but for file input
and cin i have some question for the "std::cin"

#include <iostream.h>

int main(void)
{int n, sum=0;
while(cin >> n) sum+=n;
cout << "somma = " << sum << endl;
return 0;
}

so if (cin >> n) is an object "istream" and it is not a pointer
how know "the while" when to stop the loop or to continue the loop?
i think something somethink of kind (cin >> n)!=(int)0


basic_ios::operator void *();

Returns a null pointer if fail(), otherwise non-null pointer to
signal "stream ok".

--
TB @ SWEDEN
Jun 30 '06 #2

P: n/a

"TB" <TB@SWEDEN> wrote in message
news:44***********************@news-taz.teranews.com...
ax skrev:
to implement std::cout and file output seems simple but for file input
and cin i have some question for the "std::cin"

#include <iostream.h>

int main(void)
{int n, sum=0;
while(cin >> n) sum+=n;
cout << "somma = " << sum << endl;
return 0;
}

so if (cin >> n) is an object "istream" and it is not a pointer how know
"the while" when to stop the loop or to continue the loop?
i think something somethink of kind (cin >> n)!=(int)0


basic_ios::operator void *();

Returns a null pointer if fail(), otherwise non-null pointer to
signal "stream ok".


Your answer is a little short on explanation, isn't it?

I think what you're trying to say is that there is an implicit conversion
made on the istream return value, using the operator void*() function, and
that, when the stream is in a fail state, that operator returns NULL.
Otherwise, it returns a non-NULL value. Correct?

-Howard


Jun 30 '06 #3

P: n/a
ax
On Fri, 30 Jun 2006 18:09:06 +0200, TB <TB@SWEDENwrote:
>ax
ax skrev:
>so if (cin >n) is an object "istream" and it is not a pointer
how know "the while" when to stop the loop or to continue the loop?
i think something somethink of kind (cin >n)!=(int)0

basic_ios::operator void *();

Returns a null pointer if fail(), otherwise non-null pointer to
signal "stream ok".
thank you
Jul 2 '06 #4

This discussion thread is closed

Replies have been disabled for this discussion.