> Programming Languages > C++
Various Topics Home | Disclaimer | Report Adult Posts

Various Topics on C++



C++ - "question about cin input ?" in Programming Languages


Old 06-20-2004   #1
....
 
Default question about cin input ?

The input via "cin" is string. right ?
(say string s; cin>>s1; the input accepted via cin is now stored in string s)

How to convert this into integer ?

say user inputs 99. How to covert this string (99) into integer value of 99.
 
Old 06-20-2004   #2
..ct.. ..zar..
 
Default Re: question about cin input ?

"mark" <markstone23@yahoo.com> wrote...
> The input via "cin" is string. right ?
> (say string s; cin>>s1; the input accepted via cin is now stored in

string s)
>
> How to convert this into integer ?
>
> say user inputs 99. How to covert this string (99) into integer value of

99.

Please search google groups for "convert string to integer C++"
(without the quotes).


 
Old 06-20-2004   #3
.... ..rris..
 
Default Re: question about cin input ?


"mark" <markstone23@yahoo.com> wrote in message
news:5e41994c.0406191858.6ed7b9f7@posting.google.c om...
> The input via "cin" is string. right ?


Wrong

> (say string s; cin>>s1; the input accepted via cin is now stored in

string s)

Right

>
> How to convert this into integer ?
>
> say user inputs 99. How to covert this string (99) into integer value of

99.

#include <stdlib.h>

int n = atoi(s.c_str());

There are many other ways as well.

john


 
Old 06-20-2004   #4
..anetzo..
 
Default Re: question about cin input ?

markstone23@yahoo.com (mark) wrote in
news:5e41994c.0406191858.6ed7b9f7@posting.google.c om:

> The input via "cin" is string. right ?


You can also input into an int:

int a;
cin >> a;
 

Thread Tools
Display Modes





Powered by vBulletin®
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0