473,320 Members | 1,982 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

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

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.

Jul 23 '05 #1
2 2620
qa********@rediffmail.com 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
Jul 23 '05 #2
qa********@rediffmail.com 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
Jul 23 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

12
by: Matt Garman | last post by:
I'd like to create a "custom output facility". In other words, I want an object whose use is similar to std::cout/std::cerr, but offers more flexibility. Instead of simply writing the parameter...
6
by: radnoraj | last post by:
Hi, I am sucessfull in redirecting console output to a file. but in this case nothing is displayed on the console, cout output is written to file without display. how do write the output to...
7
by: Generic Usenet Account | last post by:
I am trying to set up a delimiter character string for the input stream such that the delimiter string is "skipped over" in the input stream. Can someone suggest how to do this with some sample...
9
by: kernelxu | last post by:
hi,everybody. I calling function setbuf() to change the characteristic of standsrd input buffer. some fragment of the progrem is: (DEV-C++2.9.9.2) #include <stdio.h> #include <stdlib.h> int...
8
by: FS Liu | last post by:
Hi, I am writing ATL Service application (XML Web service) in VS.NET C++. Are there any sample programs that accept XML as input and XML as output in the web service? Thank you very much.
2
by: pelletier.thomas | last post by:
Hello everybody. I'm trying to code a very little OS. But I have a problem with the keyboard input: It show thechar + "~" :s Can you help me ? The source is there :...
14
by: n3o | last post by:
Hello Comp.Lang.C Members, I have an issue with user input that I have been trying to figure out for the longest. For instance, let's say you have something like this: void foo() { int num;...
77
by: arnuld | last post by:
1st I think of creating an array of pointers of size 100 as this is the maximum input I intend to take. I can create a fixed size array but in the end I want my array to expand at run-time to fit...
27
by: =?ISO-8859-1?Q?Tom=E1s_=D3_h=C9ilidhe?= | last post by:
I have a fully-portable C program (or at least I think I do). It works fine on Windows, but malfunctions on Linux. I suspect that there's something I don't know about the standard input stream...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.