473,714 Members | 2,513 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

converting string into integer

Hi there,

I want to convert a String into integer.

I get the string froma file using :

string argNum;
getline(inputSt ream,argNum);

I now need to convert argNum into integer.

I tried to use

int a = atoi(argNum);

But I got errot message :error: cannot convert `std::string' to `const
char*' for argument `1' to `int atoi(const char*)'

And for the getline function, the argNum must be a string variable.

Can anyone please tell me how to convert argNum into integer ?

Thank you in advance,
priya

Jul 17 '06 #1
9 2732
priyanka wrote:
Hi there,

I want to convert a String into integer.
...
But I got errot message :error: cannot convert `std::string' to `const
char*' for argument `1' to `int atoi(const char*)'
Try comp.lang.c++ down the hall. We only deal with C.

[And just in case: No, C is not a subset of C++, and no, the C solution
is
not 'okay' for a C++ program.]

--
Peter

Jul 17 '06 #2

priyanka wrote:
Hi there,

I want to convert a String into integer.

I get the string froma file using :

string argNum;
getline(inputSt ream,argNum);
What is this getline function you're speaking of ?
I now need to convert argNum into integer.

I tried to use

int a = atoi(argNum);

But I got errot message :error: cannot convert `std::string' to `const
char*' for argument `1' to `int atoi(const char*)'
Since this std::string thingy is not C you were bound to get an error.
By the way , C++ questions should be asked at comp.lang.c++
And for the getline function, the argNum must be a string variable.

Can anyone please tell me how to convert argNum into integer ?
If argNum is pointer to char , then you use atoi. In C that is.

Spiros Bousbouras

Jul 17 '06 #3
int a = atoi(argNum);

But I got errot message :error: cannot convert `std::string' to `const
char*' for argument `1' to `int atoi(const char*)'
You can use argNum.c_str() to solve this problem.
I think you are a newer to C++. This is a very basic problem. You can
find the answer in many books very easily.

Jul 18 '06 #4
"Andy" <an*****@gmail. comwrites:
>int a = atoi(argNum);

But I got errot message :error: cannot convert `std::string' to `const
char*' for argument `1' to `int atoi(const char*)'

You can use argNum.c_str() to solve this problem.
I think you are a newer to C++. This is a very basic problem. You can
find the answer in many books very easily.
The original question was posted by "priyanka" <pr**********@g mail.com>.
Please don't snip attribution lines.

If your answer involves C++, please don't post it here. comp.lang.c++
is down the hall, third door on the left, just past the water cooler.
We discuss C here, and we can't check the accuracy of any C++
information.

--
Keith Thompson (The_Other_Keit h) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <* <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
Jul 18 '06 #5
On 17 Jul 2006 17:48:03 -0700, "Andy" <an*****@gmail. comwrote in
comp.lang.c:

Please don't trim attribution lines. I've put it back:
On 17 Jul 2006 15:22:23 -0700, "priyanka" <pr**********@g mail.comwrote in comp.lang.c:
....that's better!
>
int a = atoi(argNum);

But I got errot message :error: cannot convert `std::string' to `const
char*' for argument `1' to `int atoi(const char*)'

You can use argNum.c_str() to solve this problem.
No he can't, not in C.
I think you are a newer to C++. This is a very basic problem. You can
find the answer in many books very easily.
He has a much more basic problem. He either can't distinguish between
C and C++, or he can't distinguish between comp.lang.c and
comp.lang.c++. Until he gets that issue straightened out, I foresee a
world of hurt in his future.

--
Jack Klein
Home: http://JK-Technology.Com
FAQs for
comp.lang.c http://c-faq.com/
comp.lang.c++ http://www.parashift.com/c++-faq-lite/
alt.comp.lang.l earn.c-c++
http://www.contrib.andrew.cmu.edu/~a...FAQ-acllc.html
Jul 18 '06 #6

Jack Klein wrote:
He has a much more basic problem. He either can't distinguish between
C and C++, or he can't distinguish between comp.lang.c and
comp.lang.c++. Until he gets that issue straightened out, I foresee a
world of hurt in his future.
Hmmm. In this thread, we find a quote from Keith
Thompson.
>If your answer involves C++, please don't post it here. comp.lang.c++
is down the hall, third door on the left, just past the water cooler.
We discuss C here, and we can't check the accuracy of any C++
information.
But elswhere, Keith writes:
>you're in the wrong place; comp.lang.c++ is down the
hall, just past the water cooler, first door on the left.
This leaves me completely baffled! Not only can I not
find the water cooler, but the group seems to be changing
rooms! At least I'm confident that it will be on the left side
of the hall...

Jul 18 '06 #7
sp****@gmail.co m wrote:
If argNum is pointer to char , then you use atoi. In C that is.
atoi causes undefined behaviour if the number is bigger than
the biggest possible int (or smaller than the smallest possible).

It's best to use strtol or strtoul.

Jul 18 '06 #8
Bill Pursell wrote:
Jack Klein wrote:

>>He has a much more basic problem. He either can't distinguish between
C and C++, or he can't distinguish between comp.lang.c and
comp.lang.c++ . Until he gets that issue straightened out, I foresee a
world of hurt in his future.


Hmmm. In this thread, we find a quote from Keith
Thompson.

>>If your answer involves C++, please don't post it here. comp.lang.c++
is down the hall, third door on the left, just past the water cooler.
We discuss C here, and we can't check the accuracy of any C++
information .


But elswhere, Keith writes:
>>you're in the wrong place; comp.lang.c++ is down the
hall, just past the water cooler, first door on the left.


This leaves me completely baffled! Not only can I not
find the water cooler, but the group seems to be changing
rooms! At least I'm confident that it will be on the left side
of the hall...
I thought the third door was the moderated group...

--
Ian Collins.
Jul 18 '06 #9
On 17 Jul 2006 21:44:58 -0700, in comp.lang.c , "Bill Pursell"
<bi**********@g mail.comwrote:
>>If your answer involves C++, please don't post it here. comp.lang.c++
is down the hall, third door on the left, just past the water cooler.
We discuss C here, and we can't check the accuracy of any C++
information .

But elswhere, Keith writes:
>>you're in the wrong place; comp.lang.c++ is down the
hall, just past the water cooler, first door on the left.

This leaves me completely baffled! Not only can I not
find the water cooler, but the group seems to be changing
rooms!
Its a big room. What, theatres in your town only have one way in ?
>At least I'm confident that it will be on the left side
of the hall...
And on the right...
--
Mark McIntyre

"Debugging is twice as hard as writing the code in the first place.
Therefore, if you write the code as cleverly as possible, you are,
by definition, not smart enough to debug it."
--Brian Kernighan
Jul 18 '06 #10

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

Similar topics

4
3311
by: Cyde Weys | last post by:
I'm currently working on converting a simulator program from Visual Basic 6.0 to Visual C++ .NET. I've figured out most of the stuff, but there's still one thing I haven't gotten to and I've never really had to deal with it before. I'm programming a front-end for what is a compiled Fortran program. The VB source does the following to call the Fortran: 'Defines the subroutine. Declare Sub Cycle_DW Lib "cycdw.dll" Alias "CYCDW" (ByRef...
7
8689
by: RCS | last post by:
Okay, a rather 'interesting' situation has arisen at a place I work: I need to convert a database from Access to something that can be used over the web. I am currently maintaining and developing a mid-sized Access database (60 tables, 25 simultaneous users). Although I've been tossing up if I should try to convert the back end to SQL server (We have a license), the performance has been good enough that it always seemed a waste of time,...
2
5751
by: Asbjørn Ulsberg | last post by:
Hi. I'm trying to convert Brady Hegberg's great RTF2HTML VB 6.0 module to C#. I've managed to convert the VB code to VB.NET, which gave me the following code: Option Strict On Option Explicit On Option Compare Binary
0
1765
by: Mark Allen | last post by:
Hello, I am creating an RTF document server side for a report. However I am having problems converting images into the required RTF format. I am converting the image into a string (binary) and including the image syntax as per the RTF Specification, however the image is not appearing when I view the document in Word or WordPad.
11
3003
by: Steve | last post by:
I'm hoping someone can help me out. I'm a newbie to vb.net still. I'm trying to convert the code below from VB6 to VB.NET. I'm not sure of the best way to go. This is basically a simple application to do scoring for a competition. I'm using an Access database and all of this code happens "behind the scenes" when all of the scores have been entered on another screen (that piece is done). If someone could help me, I'd really be...
4
2262
by: sal | last post by:
Greets, All Converting array formula to work with datatables/dataset tia sal I finally completed a formula I was working on, see working code below. I would like to change this code so it will work with a variable mutl- row, 5 column datatable where the users select items. Anyone have any suggestions on where to start? Or changes in the current code that might be made.
13
3962
by: Paraic Gallagher | last post by:
Hi, This is my first post to the list, I hope somebody can help me with this problem. Apologies if it has been posted before but I have been internet searching to no avail. What I am trying to do is provide a simple method for a user to change a config file, for a test suite. The config file consists of a number of keys, eg. build number, target device, etc.
12
2601
by: Rob Meade | last post by:
Hi all, Ok - I've come from a 1.1 background - and previously I've never had any problem with doing this: Response.Write (Session("MyDate").ToString("dd/MM/yyyy")) So, I might get this for example: 21/05/2006
9
2576
by: Terry | last post by:
I am converting (attempting) some vb6 code that makes vast use of interfaces. One of the major uses is to be able to split out Read-only access to an obect. Let me give you a simple (contrived) example: In Project RoObjDefs: RoPerson.cls file: Public Property Get FirstName() as String Public Property Get LastName() as String <end of file RoPerson.cls> RoPersons.cls file Public Function Count() as Integer
2
4797
by: Alex Buell | last post by:
Is there an elegant way of converting strings containing digits between different number bases in C++? I.e.: 10 (base 2) = 2 (base 10) FF (base 16) = 256 (base 10) F (base 16) = 1111 (base 2) etc? Thanks, Alex
0
8797
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9171
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9071
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9010
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7946
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
4462
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4717
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3156
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2514
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.