Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > how to convert string to integer??

Reply
Thread Tools

how to convert string to integer??

 
 
news.hku.hk
Guest
Posts: n/a
 
      04-24-2004
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~


 
Reply With Quote
 
 
 
 
Aggro
Guest
Posts: n/a
 
      04-24-2004
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
 
Reply With Quote
 
 
 
 
marbac
Guest
Posts: n/a
 
      04-24-2004
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;
}
 
Reply With Quote
 
Rakesh Kumar
Guest
Posts: n/a
 
      04-25-2004


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 **
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: How include a large array? Edward A. Falk C Programming 1 04-04-2013 08:07 PM
Convert formatted string to string? rockdale ASP .Net 3 04-12-2006 03:01 PM
convert string to raw string? Phd Python 3 12-06-2004 04:36 PM
Connection String object Convert to String Variable Type =?Utf-8?B?TWlrZSBNb29yZQ==?= ASP .Net 2 10-26-2004 02:43 PM
Convert string to a string array Andrew Banks ASP .Net 2 04-19-2004 04:45 PM



Advertisments