Results 1 to 4 of 4

Thread: c++ char to Int

  1. #1
    Join Date
    Jan 2006
    Posts
    976
    Thanks
    53
    Qt products
    Qt3
    Platforms
    Windows

    Default c++ char to Int

    I I'm trying to to convert var a to int with this, but dosn't work? is the use of strtol correct? thanks
    Qt Code:
    1. char * pEnd;
    2. int num;
    3. const char* a = "v"; //why with 'v' doesn't compile????
    4. num = strtol (a, &pEnd, 10);
    5. cout << " num " << num << endl; //it print alway 0
    6. }
    To copy to clipboard, switch view to plain text mode 
    Regards

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: c++ char to Int

    Quote Originally Posted by mickey View Post
    const char* a = "v"; //why with 'v' doesn't compile????
    Because 'v' is "char" not "char *".

    Quote Originally Posted by mickey View Post
    it print alway 0
    Did you try to use some valid number (like "1") instead of "v"?

  3. The following user says thank you to jacek for this useful post:

    mickey (5th October 2006)

  4. #3
    Join Date
    Jan 2006
    Posts
    976
    Thanks
    53
    Qt products
    Qt3
    Platforms
    Windows

    Default Re: c++ char to Int

    Quote Originally Posted by jacek View Post
    Because 'v' is "char" not "char *".
    Did you try to use some valid number (like "1") instead of "v"?
    yes in that way work (it print 1); but I knew any char has a in value(eg 'a' =16; b='17', B=32). I'd like to obtain that number....maybe I'm doing the wrong question......
    Regards

  5. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: c++ char to Int

    Quote Originally Posted by mickey View Post
    any char has a in value(eg 'a' =16; b='17', B=32). I'd like to obtain that number...
    In that case you don't need any functions:
    Qt Code:
    1. char c = 'v';
    2. int v = c;
    To copy to clipboard, switch view to plain text mode 

  6. The following user says thank you to jacek for this useful post:

    mickey (5th October 2006)

Similar Threads

  1. Current char in QTextEdit
    By jlbrd in forum Qt Programming
    Replies: 1
    Last Post: 12th August 2006, 09:30
  2. QString to char
    By boss_bhat in forum Qt Programming
    Replies: 7
    Last Post: 20th July 2006, 23:26
  3. Howq to get the ascii of a char ?
    By yellowmat in forum Newbie
    Replies: 2
    Last Post: 27th April 2006, 21:05
  4. How to get size (length, width ....) of string or char
    By Krishnacins in forum Qt Programming
    Replies: 1
    Last Post: 20th March 2006, 09:55
  5. Problems with Q_OBJECT and subclassing
    By renaissanz in forum Qt Programming
    Replies: 4
    Last Post: 21st February 2006, 22:18

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.