question about cin input ?

M

mark

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.
 
V

Victor Bazarov

mark said:
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).
 
J

John Harrison

mark said:
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
 
P

Prateek R Karandikar

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.

Why beat around the bush when you can directly input to an int?

int x;
cin>>x;

-- --
To iterate is human, to recurse divine.
-L. Peter Deutsch
-- --
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,576
Members
45,054
Latest member
LucyCarper

Latest Threads

Top