473,756 Members | 7,817 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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("1234567 89");

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

return 0;
}

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

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<iostre am>
#include<string >

using namespace std;

int main () {
int integer;
string buffer = "123456789" ;
cout << "String:" << buffer << endl;
integer=atoi(bu ffer.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
11614
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, SqlDbType.Int, 5).Value = (theZip - 10) ....Parameter.Add(@ziphigh, SqlDbType.Int, 5).Value = (theZip + 10) SELECT * from ZIPCODES where Cast(zip_code as Integer) BETWEEN @lowzip AND @highzip
3
2379
by: winthux | last post by:
How can I convert string i.e. to integer or to unsigned integer, or to other types?
16
117260
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 integer value of 3 and write into a string buffer. What I did: .....
5
3434
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: unsupported operand type(s) for /=: 'unicode' and 'int' I want to divide x by 10 and assign that value back to x.
43
8451
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 is not extremely convenient. -- NOUN:1. Money or property bequeathed to another by will. 2. Something handed down from an ancestor or a predecessor or from the past: a legacy of religious freedom. ETYMOLOGY: MidE legacie, office of a deputy,...
10
5656
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 this be done. Below is some of my code. typedef void (*funcptr)(void); void tryme(void){};
27
2830
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
8250
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
2902
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 Equals tlb1.OfferNo _ And tlb.SIR_AlterationNo Equals tlb1.PORevNo _ Order By tlb.SIR_Flag _ Select _ SIRID = tlb.Marketing_SalesInquiryRegister_ID, _ ...
0
9456
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
9275
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10040
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
9846
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
8713
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...
1
7248
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5142
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...
1
3806
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
3359
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.