Groups | Blog | Home
all groups > dotnet framework > june 2007 >

dotnet framework : How can I make Console::ReadLine accepts int? In other words.


Peter Duniho
6/29/2007 2:59:02 PM
On Fri, 29 Jun 2007 14:30:07 -0700, Allen Maki <allenmaki@sbcglobal.net>=
=

[quoted text, click to view]

You can use the Parse() or Convert() methods to convert a string to an i=
nt.

Allen Maki
6/29/2007 9:30:07 PM
Hi everybody,

I need your help.

I am using Visual C++ .NET

How can I make Console::ReadLine accepts int? In other words.

I know I can do this:

string* =3D Console::ReadLine();

Can anybody tell me how can I do this:

Jesse Houwing
6/30/2007 5:10:16 PM
* Allen Maki wrote, On 29-6-2007 23:30:
[quoted text, click to view]

In C# it would be something like this:

string i = Console.ReadLine();
int ii = -1;
if ( int32.TryParse(i, NumberStyles.Integer, out ii) )
{
// do stuff with ii
}
else
{
// print error?
}


It shouldn't be hard to convert that to c++ I guess.

Jesse

PS: Please, do not double post (one message for every group), but if you
absolutely need to post in different newsgroups at the same time, cross
post (address one message to multiple groups at once). That way answers
AddThis Social Bookmark Button