Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > Is input/output stream buffer behaviour random acc. to C++ standard?

Reply
Thread Tools

Is input/output stream buffer behaviour random acc. to C++ standard?

 
 
qazmlp1209@rediffmail.com
Guest
Posts: n/a
 
      05-29-2005
FAQ at
"http://www.parashift.com/c++-faq-lite/input-output.html#faq-15.6"
states that the following program will not work properly:
---------------
int main()
{
char name[1000];
int age;

for (;
{
std::cout<< "Name: ";
std::cin >> name;
std::cout<< "Age: ";
std::cin >> age;
}
}
---------------

But,if I run the above program on my machine, it works without any
problems. So, does it mean that, keeping the 'non-digit character
within buffer' problem is a random behaviour exhibited by some/all
systems? I could understand that, 'ignore()' of non-digit characters
that are left behind, is safer. But, I would like to know what exactly
is the case without that.

 
Reply With Quote
 
 
 
 
Victor Bazarov
Guest
Posts: n/a
 
      05-29-2005
http://www.velocityreviews.com/forums/(E-Mail Removed) wrote:
> FAQ at
> "http://www.parashift.com/c++-faq-lite/input-output.html#faq-15.6"
> states that the following program will not work properly:
> ---------------
> int main()
> {
> char name[1000];
> int age;
>
> for (;
> {
> std::cout<< "Name: ";
> std::cin >> name;
> std::cout<< "Age: ";
> std::cin >> age;
> }
> }
> ---------------
>
> But,if I run the above program on my machine, it works without any
> problems.


What input are you giving it?

> So, does it mean that, keeping the 'non-digit character
> within buffer' problem is a random behaviour exhibited by some/all
> systems?


No.

> I could understand that, 'ignore()' of non-digit characters
> that are left behind, is safer. But, I would like to know what exactly
> is the case without that.


Try giving it some garbage instead of an integer when 'age' is requested.

V


 
Reply With Quote
 
 
 
 
Larry I Smith
Guest
Posts: n/a
 
      05-29-2005
(E-Mail Removed) wrote:
> FAQ at
> "http://www.parashift.com/c++-faq-lite/input-output.html#faq-15.6"
> states that the following program will not work properly:
> ---------------
> int main()
> {
> char name[1000];
> int age;
>
> for (;
> {
> std::cout<< "Name: ";
> std::cin >> name;
> std::cout<< "Age: ";
> std::cin >> age;
> }
> }
> ---------------
>
> But,if I run the above program on my machine, it works without any
> problems. So, does it mean that, keeping the 'non-digit character
> within buffer' problem is a random behaviour exhibited by some/all
> systems? I could understand that, 'ignore()' of non-digit characters
> that are left behind, is safer. But, I would like to know what exactly
> is the case without that.
>


Does it work correctly when you enter "abc" or "9 xx" in response
to the "Age:" prompt?

Regards,
Larry
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Math.random() and Math.round(Math.random()) and Math.floor(Math.random()*2) VK Javascript 15 05-02-2010 03:43 PM
When using System.IO.FileStream, I write 8 bytes, then seek to the start of the file, does the 8 bytes get flushed on seek and the buffer become a readbuffer at that point instead of being a write buffer? DR ASP .Net 2 07-29-2008 09:50 AM
random.random(), random not defined!? globalrev Python 4 04-20-2008 08:12 AM
convert M bit buffer to N bit buffer runcyclexcski@yahoo.com C++ 2 03-26-2007 09:43 AM
How to know the buffer size and increase buffer size in c++ Raja C++ 12 06-21-2004 06:21 PM



Advertisments