Results 1 to 7 of 7

Thread: how to change from "CString" to "long"??

  1. #1

    Thread Starter
    Member
    Join Date
    Sep 2002
    Location
    in e middle of nowhere..
    Posts
    40

    Question how to change from "CString" to "long"??

    hello..
    may i know how to change type from CString to long??

    eg., CString------> "123"
    to
    long --------> 123

    is it possible?
    pls... help.. sos..

  2. #2
    Addicted Member HairyDave's Avatar
    Join Date
    Aug 2002
    Location
    Er...I can't remember.
    Posts
    196
    Use the atol function:

    CString str = "123";
    long val;

    val = atoi(str);
    // val = 123

    Hope it helps

    HD

  3. #3

    Thread Starter
    Member
    Join Date
    Sep 2002
    Location
    in e middle of nowhere..
    Posts
    40
    thanks..

  4. #4
    Hyperactive Member
    Join Date
    Sep 2001
    Posts
    396
    Originally posted by HairyDave
    Use the atol function:

    CString str = "123";
    long val;

    val = atoi(str);
    // val = 123

    Hope it helps

    HD
    I don't think atoi() takes a CString object as its parameter.

    Hazel can try

    int val=atoi((LPCTSTR)str);

    Hope it helps.

  5. #5
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    CString is automatically converted to LPCTSTR so it works without the explicit cast.
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

  6. #6

    Thread Starter
    Member
    Join Date
    Sep 2002
    Location
    in e middle of nowhere..
    Posts
    40
    hey thank you all guyz!
    but "atol" doesn't work or there's something wrong wih my program, i cant get the value...

    ok..anyway..thanks..
    i'll try again..

  7. #7

    Thread Starter
    Member
    Join Date
    Sep 2002
    Location
    in e middle of nowhere..
    Posts
    40
    hi..
    i put some update statements and now my program can work..
    thanks for the help..


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