CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 8 of 8
  1. #1
    Join Date
    May 1999
    Posts
    24

    How to convert a Cstring into a int ?

    I would like to know how to convert a Cstring into a int.
    Thanks a lot

    Philippe.


  2. #2
    Join Date
    May 1999
    Location
    Miami, Florida
    Posts
    242

    Re: How to convert a Cstring into a int ?


    int value;

    sprintf(value, "%i", strText);


  3. #3
    Join Date
    May 1999
    Posts
    6

    Re: How to convert a Cstring into a int ?

    use the function atoi(). (ascii to int)
    for example:
    CString string = "40";
    int zahl = atoi(string); // converts string to int

    ...this should help you.










  4. #4
    Join Date
    May 1999
    Posts
    24

    Re: How to convert a Cstring into a int ?

    Danke sehr Rocky.


  5. #5
    Join Date
    May 1999
    Location
    Karnataka, India
    Posts
    33

    Re: How to convert a Cstring into a int ?

    CString l_str;
    int l_iVar;

    l_str.Format("%d", l_iVar);

    hope this should help you.


    Regards,
    Sanjay
    [email protected]

  6. #6
    Guest

    Re: How to convert a Cstring into a int ?

    int sprintf( char *buffer, const char *format [, argument] ... );

    This is the prototype for sprintf function.

    So your the code below won't compile at all.
    Also, you are not doing exactly what the question is.


    int value;

    sprintf(value, "%i", strText);






  7. #7
    Join Date
    May 1999
    Location
    TamilNadu, India
    Posts
    42

    Re: How to convert a Cstring into a int ?

    use atoi(CString ) to convert a CString object to an integer....
    Thanks lot,
    Srini


  8. #8
    Join Date
    May 1999
    Location
    Malaysia
    Posts
    99

    Re: How to convert a Cstring into a int ?

    you can use function strcpy(CString, char) to convert the Cstring to character first, and then use function atoi(*char ) to convert the character to int.

    CString---->Character----->interger

    email me to let me know your progress

    ty

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured