473,666 Members | 2,238 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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

FAQ at
"http://www.parashift.c om/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 2653
qa********@redi ffmail.com wrote:
FAQ at
"http://www.parashift.c om/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********@redi ffmail.com wrote:
FAQ at
"http://www.parashift.c om/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
3197
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 to stdout/stderr, I'd like it to write to stdout, to a file, and/or call a logging function. So my output function might look something like this: OutputFacility& OutputFacility::put(const std::string& s) { cout << s; // print to stdout
6
4607
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 console as well as to file, my code is as below, ======================================================================= #include <iostream.h> #include<ostream> #include<sstream>
7
4079
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 code? I am attaching a "C" code snippet that does the same thing. The problem is that I don't know how to realize this using "cin" Thanks, Lee
9
3996
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 main(void) { char buf = {0};
8
2574
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
2070
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 : http://thonix.tuxfamily.org/pub/0.0.1/src/
14
2399
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; printf("Please enter a number: "); scanf("%d", &num); // yes I know this function may throw a
77
3329
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 the size of input. I am not able to come up with anyting all all and doing: char* arr_of_pointers; seems like a completely wrong idea as this is a static array. I want to take the input and then decide how much memory I need and then malloc...
27
3131
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 that's causing the problem. Here's how I wrote the program originally: #include <stdio.h> #include <string.h>
0
8355
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8866
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8550
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8638
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6191
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5662
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4193
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
2769
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2006
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.