473,378 Members | 1,446 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,378 software developers and data experts.

Why am I getting garbage?

//Hi there,

//I need help.

//If I run the program and entered 100 at the prompt, I will get 45

//(garbage).

//Can anybody tell me what am I doing wrong? And how it can be corrected?

#include "stdafx.h"

#using <mscorlib.dll>

using namespace System;

using namespace System::IO;

int _tmain()

{

//Read from Screen

Int32 K = Console::Read();

Console::Write(K);

return 0;
Feb 6 '07 #1
2 878

"Allen Maki" <al*******@sbcglobal.netwrote in message
news:Wg******************@newssvr29.news.prodigy.n et...
//Hi there,

//I need help.

//If I run the program and entered 100 at the prompt, I will get 45

//(garbage).

//Can anybody tell me what am I doing wrong? And how it can be corrected?

#include "stdafx.h"

#using <mscorlib.dll>

using namespace System;

using namespace System::IO;

int _tmain()

{

//Read from Screen

Int32 K = Console::Read();

Console::Write(K);

return 0;
Start with the fact that the Read method does not read from the screen. It
reads the next character in the input stream.
The default input device is the keyboard.

http://msdn2.microsoft.com/en-us/lib...sole.read.aspx

Check the example code in the article. It should lead you in the right
direction.
Feb 6 '07 #2
Allen Maki wrote:
Int32 K = Console::Read();
How would Read know that you want to read a string and convert it into
integer? Read reads a single character and returns its code. In your
case, 45 means you hit the - key.

To read a string, use ReadLine, after which you can use Int32::Parse to
convert it into integer.

http://msdn2.microsoft.com/en-us/lib....readline.aspx
http://msdn2.microsoft.com/en-gb/lib...t32.parse.aspx

Tom
Feb 6 '07 #3

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

Similar topics

3
by: Bryan | last post by:
I've been messing around with a C++ application on Xbox, and have been encountering problems with my objects getting garbage collected when they go out of scope, but before I'm actually done using...
10
by: pachanga | last post by:
The Hans-Boehm garbage collector can be successfully used with C and C++, but not yet a standard for C++.. Is there talks about Garbage Collector to become in the C++ standard?
14
by: John J. Hughes II | last post by:
Using the below code I am send multiple sterilized object across an IP port. This works fine if only one object is received at a time but with packing sometimes there is more then one object or...
2
by: Paul Bromley | last post by:
I thought that it would be very easy to get basic settings from a PC such as OS version, amount of free disk space, computer name, memory, processor etc, but this sodes not seem as easy as I...
12
by: leonard.guillaume | last post by:
Hi guys, I use dynamic char arrays and I'm trying to get rid of the garbage in it. Let me show you the code and then I'll explain more in details. ...
28
by: Goalie_Ca | last post by:
I have been reading (or at least googling) about the potential addition of optional garbage collection to C++0x. There are numerous myths and whatnot with very little detailed information. Will...
22
by: Sri | last post by:
All Recenetly our shop migrated to DB2 V8 from V7. We are in IBM System Level: z/OS 1.6.1 @ RSU 0702. Processor : IBM 2064-1C7 (z/900) # 1B89 Mode: 64-bit One of my application is facing...
56
by: Johnny E. Jensen | last post by:
Hellow I'am not sure what to think about the Garbage Collector. I have a Class OutlookObject, It have two private variables. Private Microsoft.Office.Interop.Outlook.Application _Application =...
8
by: =?Utf-8?B?Z3JlYXRiYXJyaWVyODY=?= | last post by:
Hi, I'm completely stumped on this but i want to create something that can get the md5 value of an EXE based on the passed in argument and compare it to the specified MD5. I can do the...
158
by: pushpakulkar | last post by:
Hi all, Is garbage collection possible in C++. It doesn't come as part of language support. Is there any specific reason for the same due to the way the language is designed. Or it is...
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...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.