473,387 Members | 3,820 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,387 software developers and data experts.

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.
Jul 22 '05 #1
4 1074
"mark" <ma*********@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).
Jul 22 '05 #2

"mark" <ma*********@yahoo.com> wrote in message
news:5e**************************@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
Jul 22 '05 #3
ma*********@yahoo.com (mark) wrote in
news:5e**************************@posting.google.c om:
The input via "cin" is string. right ?


You can also input into an int:

int a;
cin >> a;
Jul 22 '05 #4
ma*********@yahoo.com (mark) wrote in message news:<5e**************************@posting.google. com>...
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
-- --
Jul 22 '05 #5

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

Similar topics

0
by: John Wilson | last post by:
Hello, I have the following code which populates as table data from a SQL Server 2000 stored proc (RSByDemoID2). Below that is the view and stored procedure which takes @DemoID as input to match...
7
by: Kevin Stern | last post by:
Hi All, Here is a program I wrote and compiled using g++ #include <iostream> int main() { char a; std::cin.get(a); std::cout << a; std::cin.ignore(100, '\n');
9
by: LNM | last post by:
I am trying to create a survey type form where multiple choice answers are selected (radios) and I am using an onclick event to update a text box with 'correct', etc. I am using the...
0
by: robert | last post by:
Hi all, I'm having a hard time resolving a namespace issue in my wsdl. Here's an element that explains my question, with the full wsdl below: <definitions name="MaragatoService"...
13
by: Eric_Dexter | last post by:
All I am after realy is to change this reline = re.line.split('instr', '/d$') into something that grabs any line with instr in it take all the numbers and then grab any comment that may or may...
2
by: gdarian216 | last post by:
the object of the project was to create a program that inputs multiple lines of integers and outputs them in an HTML table. The negative numbers should be red. The numbers should be printed 3 in a...
4
by: Engineerik | last post by:
I am trying to create a socket server which will listen for connections from multiple clients and call subroutines in a Fortran DLL and pass the results back to the client. The asynchronous socket...
5
by: theflyingminstrel | last post by:
Hi I have a question, it's probably very basic but I'm still learning the Javascript basics. The following form outputs a string change (from "input" to "text" box ). When the word "test" is...
2
by: robtyketto | last post by:
Greetings, Within my jsp I have HTML code (see below) which accepts input, one of these fields sequence unlike the others is an Integer. <FORM ACTION="wk465682AddFAQ.jsp" METHOD="POST"> Id:...
2
by: subramanian100in | last post by:
Consider the following program named as x.c #include <stdlib.h> #include <stdio.h> int main(void) { unsigned int u; char str;
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
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: 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...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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,...

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.