How cin or scanf works

Write here if you have problems with your C++ source code

Moderator: Board moderators

Post Reply
User avatar
A1
Experienced poster
Posts: 173
Joined: Wed Jan 28, 2004 3:34 pm
Location: Bangladesh

How cin or scanf works

Post by A1 » Wed Feb 08, 2006 1:38 pm

Lets i have a code like this:

Code: Select all

#include <iostream.h>

int main()
{
	int x;
	char s[100];

	cin>>x;
	cin>>s;
	cout<<x<<" "<<s<<endl;
	return 0;
}
And my input is:

Code: Select all

123nospace
The Output of this program is:

Code: Select all

123 nospace
Here my question is how cin or scanf() stop reading immediately before a non numeric character when it reads a number?
Does they change input pointer?
(Actually i want to implement this kind of function in java, is it possible?)

User avatar
A1
Experienced poster
Posts: 173
Joined: Wed Jan 28, 2004 3:34 pm
Location: Bangladesh

Post by A1 » Tue Feb 14, 2006 3:53 pm

I belive some body knows some thing about this :-? :roll:
or any links that can help me..

Moha
Experienced poster
Posts: 216
Joined: Tue Aug 31, 2004 1:02 am
Location: Tehran
Contact:

Post by Moha » Wed Apr 05, 2006 11:03 pm

They have a buffer and see the next character.
Also you can see the next character without extracting it from buffer.

Post Reply

Return to “C++”