RE: [Dev-C++] string conversion to integer
Open Source C & C++ IDE for Windows
Brought to you by:
claplace
|
From: James G. <Jam...@Cl...> - 2001-01-22 10:05:25
|
Try this:
#include <stdio.h>
#include <stdlib.h>
#include <string>
using namespace std;
int main(int argc, char *argv[])
{
// C++ String
string input_string = "123456";
int conv_number = 0;
// c_str() returns a char*
conv_number = atoi(input_string.c_str());
cout << "String converted to a number = " << conv_number << endl;
cout << "conv_number + 100 = " << conv_number + 100 << endl;
return 0;
}
Regards,
James.
-----Original Message-----
From: Alan Thomas [mailto:ala...@3n...]
Sent: Saturday, January 20, 2001 4:27 PM
To: dev...@li...
Subject: [Dev-C++] string conversion to integer
I thought I knew how to convert string objects to integer. I
thought a character (e.g., input_string[2] of object string input_string)
could be referenced in a string and converted using the C ASCII-to-integer
function atoi. However, the compiler doesn`t like that and apparently does
not see an element of a string array as a character.
How do you do this? Thanks, Alan
_______________________________________________
Dev-cpp-users mailing list
Dev...@li...
http://lists.sourceforge.net/lists/listinfo/dev-cpp-users
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
This electronic message and any attachment is intended to be
read by the named addressee(s) only.
Any other recipient should be aware that its contents may be
legally privileged and/or confidential and that its use,
disclosure, copying or distribution may be unlawful.
Unless you are a named addressee, please delete this message
Whilst C. & J. Clark International Limited has taken steps
to prevent the transmission of computer viruses with electronic mail,
responsibility for screening incoming messages and the risk of such
transmission and its consequences lies with the recipient.
C. & J. Clark International Limited
Registered in England and Wales
Company No. 141015
Registered Office: 40 High Street, Street, Somerset BA16 0YA
Telephone: +44 (0) 1458 443131
Fax: +44 (0) 1458 447547
|