how to convert string to integer??

Discussion in 'C++' started by news.hku.hk, Apr 24, 2004.

  1. news.hku.hk

    news.hku.hk Guest

    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~
     
    news.hku.hk, Apr 24, 2004
    #1
    1. Advertising

  2. news.hku.hk

    Aggro Guest

    Aggro, Apr 24, 2004
    #2
    1. Advertising

  3. news.hku.hk

    marbac Guest

    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;
    }
     
    marbac, Apr 24, 2004
    #3
  4. news.hku.hk

    Rakesh Kumar Guest

    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 **
     
    Rakesh Kumar, Apr 25, 2004
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Jon Paskett

    Convert a Base32 string to Base10 integer

    Jon Paskett, Dec 18, 2005, in forum: ASP .Net
    Replies:
    1
    Views:
    1,168
    Nathan Sokalski
    Dec 18, 2005
  2. Azmie
    Replies:
    12
    Views:
    1,068,782
    Azmie
    Dec 30, 2003
  3. les ander
    Replies:
    4
    Views:
    921
    wes weston
    Oct 5, 2004
  4. news
    Replies:
    2
    Views:
    1,134
  5. Randy Kramer
    Replies:
    12
    Views:
    403
    Robert Klemme
    Oct 25, 2007
Loading...

Share This Page