473,378 Members | 1,512 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,378 software developers and data experts.

how to convert string to integer??

could you tell me how can i convet a string to integer??

#include <iostream>
#include <string>
using namespace std;

int main(){
int integer;
string buffer("123456789");

integer = buffer.substr(2, 4); // how to store the number as integer??

return 0;
}

Thanks a lot~
Jul 22 '05 #1
3 27530
news.hku.hk wrote:
int integer;
string buffer("123456789");

integer = buffer.substr(2, 4); // how to store the number as integer??


Save the substring into a string and then convert string into integer.
See the faq [38.2] How do I convert a std::string to a number?:

http://www.parashift.com/c++-faq-lit....html#faq-38.2
Jul 22 '05 #2
news.hku.hk schrieb:
could you tell me how can i convet a string to integer??


stdlib:
int atoi ( const char * string );
Convert string to integer.
Parses string interpreting its content as a number and returns an int
value.


#include<iostream>
#include<string>

using namespace std;

int main () {
int integer;
string buffer = "123456789";
cout << "String:" << buffer << endl;
integer=atoi(buffer.c_str());
cout << "Integer:" << integer << endl;
return 0;
}
Jul 22 '05 #3


marbac wrote:
news.hku.hk schrieb:
could you tell me how can i convet a string to integer??


stdlib:
int atoi ( const char * string );


long atol(const char *nptr);
double atof(const char *nptr);

- Use these two functions in case you are looking for a long or a
double (instead of an int).

HTH

--
Rakesh Kumar
** Remove nospamplz from my email address for my real email **
Jul 22 '05 #4

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

Similar topics

5
by: Anton | last post by:
I have a table of zip codes, some with Canadian zips. I'd like to take a zip code and search for nearby zips. For example: Dim theZip As Integer = textbox1.text ....Parameter.Add(@ziplow,...
3
by: winthux | last post by:
How can I convert string i.e. to integer or to unsigned integer, or to other types?
16
by: akarui.tomodachi | last post by:
What is the most easiest way to convert an integer value to ASCII character format ? I tried with sprintf(). It works. Is there any other way to do that ? Objective:: I like to convert an...
5
by: Allerdyce.John | last post by:
Do I need to convert string to integer in python? or it will do it for me (since dynamic type)? In my python script, I have this line: x /= 10; when i run it, I get this error: TypeError:...
43
by: Steven T. Hatton | last post by:
http://public.research.att.com/~bs/bs_faq2.html#int-to-string Is there no C library function that will take an int and convert it to its ascii representation? The example Bjarne shows in his faq...
10
by: rodrigo.gloria | last post by:
I am trying to convert a integer to an address of a function pointer. I want to encrypt the pointer and then do some validation, afterwards i will decrpyt the pointer back to an address. Can...
27
by: fdu.xiaojf | last post by:
Hi, String formatting can be used to converting an integer to its octal or hexadecimal form: '307' 'c7' But, can string formatting be used to convert an integer to its binary form ?
9
by: engteng | last post by:
How do I convert string to numeric in VB.NET 2003 ? Example convert P50001 to 50001 or 50001P to 50001 but if P is in middle then not convert. Regards, Tee
3
by: tanishka singh | last post by:
How do you convert string from database into date in asp.net? Dim output = (From tlb In obj.SelectRecordAll_SalesInquiryRegister _ Join tlb1 In LatestPOs On tlb.SIR_OfferNo...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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...

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.