473,442 Members | 4,386 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

leading zeros - wrong int

//please tell me why...
//and give me a hint to solve the problem with leading zeros.

//snippet
#include <iostream.h>
#include <conio.h>
int main()
{
int zahl = 0;
cout << "Give me an int please: ";
cin >> zahl;
cout << "int = " << zahl <<endl;
getch();
return 0;
}
//examples with leading zeros:
//input 0045 screen output 37
//input 0049 output 4
// 094 0
//and so on
//thank you
Jul 22 '05 #1
2 2674

"r.magdeburg" <r.*********@arcor.de> wrote in message news:3f***********************@news.freenet.de...
//please tell me why...
//and give me a hint to solve the problem with leading zeros.

When basefield is not set "senses" the base by looking at the leading digits similar to the
way literal numbers works in the language. Leading zeros cause it to treat
the base as octal. You can fix it by forcing dec, cin >> dec >> zahl;

I'm pretty sure the basefield is supposed to be dec by default...I think it's a defect in your
compiler.
Jul 22 '05 #2
r.magdeburg wrote:
//please tell me why...
//and give me a hint to solve the problem with leading zeros.

//snippet
#include <iostream.h>
#include <conio.h>
int main()
{
int zahl = 0;
cout << "Give me an int please: ";
cin >> zahl;
cout << "int = " << zahl <<endl;
getch();
return 0;
}
//examples with leading zeros:
//input 0045 screen output 37
//input 0049 output 4
// 094 0
//and so on
//thank you


Also, iostream.h is deprecated. Use:

#include <iostream> // new header. Note we don't use conio.h
#include <limits> // new header. needed for input flush
using namespace std;
int main()
{
int zahl = 0;
cout << "Give me an int please: ";
cin >> zahl;
cout << "int = " << zahl <<endl;
cin.ignore(numeric_limits<std::streamsize>::max(), '\n'); // call lifted from Josuttis The C++ Standard Library, pg. 609
return 0;
}

Jul 22 '05 #3

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

Similar topics

6
by: david | last post by:
Hi, I have an application as follows: MySQL database Back-Eend linked to MS Access Front-End and ASP Web Application. I require users to enter Serial Numbers such as: 0105123567 (10...
5
by: samik_tanik | last post by:
I need to export a datagrid to Excel. I could did this. But, also need to keep the leading zeros in the data. How can I acheive this? Any help would be appreciated. -- Thanking you in...
1
by: mmmgood1 | last post by:
Help, I'm linking an excel spreadsheet in access and I have datafields with leading zeros (01021). When the file is linked in access, I get a #num in the field with the leading zeros. The zeros...
6
by: Clint Stowers | last post by:
Using A2k Exporting a query to a CSV file. The problem is any text fields (i.e. 000345) lose any leading zeros. Exporting to an excel file this problem does not exist. Tried to create a...
6
by: Rich Raffenetti | last post by:
How can one format an integer into a hex string with leading zeros? Suppose an integer is 512 which in Hex is 200. I wish to print the 4-byte integer as 0200 or even 0x0200. The HEX function...
5
by: GarryJones | last post by:
I have code numbers in 2 fields from a table which correspond to month and date. (Month, Code number) Field name = ml_mna 1 2 3 etc up to 12 (Data is entered without a leading zero)
6
by: JimmyKoolPantz | last post by:
Task: Customer wants a script of the data that was processed in a "CSV" file. Problem: Zip-Code leading zeros are dropped Basically we have a client that has requested a custom script for...
0
by: Monty | last post by:
Hi All, I am having a problem with leading zeros being stripped from fields in a CSV file when I bring them in using Jet/OleDB. In VB.Net/VS 2008, I am accessing a CSV file like so: sSQL =...
2
by: Pete Forman | last post by:
I'm holding off installing Python 2.6, waiting for some packages to become available for it. I wonder if someone could tell me the best way to avoid future problems parsing decimal integers with...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
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,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
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...
0
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
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...
0
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...

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.