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. 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 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 This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
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
|
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>
|
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
|
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};
|
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.
| |
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/
|
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
|
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...
|
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>
|
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,...
|
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...
| |
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,...
|
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...
|
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...
|
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();...
|
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...
|
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
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |