Results 1 to 13 of 13

Thread: How to convert int to char?

  1. #1
    Join Date
    Aug 2010
    Posts
    107
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default How to convert int to char?

    I have an integer and I want to convert it into char but keeping its value!! !!!

    How to do that?
    Last edited by Bong.Da.City; 22nd December 2010 at 18:41.

  2. #2
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: How to convert int to char?


  3. #3
    Join Date
    Aug 2010
    Posts
    107
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How to convert int to char?

    i google it but what i found didn't work... anyway delete the post because you do not want to answer

  4. #4
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: How to convert int to char?

    Quote Originally Posted by Bong.Da.City View Post
    anyway delete the post
    Mine or yours?

  5. #5
    Join Date
    Sep 2009
    Location
    UK
    Posts
    2,447
    Thanks
    6
    Thanked 348 Times in 333 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: How to convert int to char?

    What you are asking for is impossible. Ints hold bigger numbers that chars, unless you are working on a system where the sizeof(int) is the same as sizeof(char).

    What are you trying to do?

  6. #6
    Join Date
    Jan 2006
    Location
    Belgium
    Posts
    1,938
    Thanked 268 Times in 268 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Wiki edits
    20

    Default Re: How to convert int to char?

    Most compilers accept the itoa(...) function

  7. #7
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: How to convert int to char?

    Special trained in understanding questions, he wants:
    Qt Code:
    1. char *c;
    2. int i = 12345;
    3. // here do the magic here with i and c.
    4. cout << c; // this should print: 12345.
    To copy to clipboard, switch view to plain text mode 
    But as told: google is nice to you if you ask it or simply grab the documentation for Qt and start with the QString documentation.

  8. #8
    Join Date
    Apr 2010
    Posts
    769
    Thanks
    1
    Thanked 94 Times in 86 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Re: How to convert int to char?

    In addition to the above, C++ stringstreams solve this problem nicely.

    Assuming the problem has been interpreted correctly. It's really impossible to decipher the original post.

  9. #9
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: How to convert int to char?

    Quote Originally Posted by SixDegrees View Post
    In addition to the above, C++ stringstreams solve this problem nicely.
    And so does QTextStream.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  10. #10
    Join Date
    Jun 2012
    Posts
    6
    Thanks
    6
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: How to convert int to char?

    It is always funny how on forums people tell you to Google something. When in fact Google returns this as the first result and usually results for other things.

  11. #11
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,230
    Thanks
    302
    Thanked 864 Times in 851 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: How to convert int to char?

    Ah, but you see this is an example of metahistory. At the time of the original post, this post didn't exist in Google's list of results. So if you click on the lmgtfy link in Lykurg's first reply, you pass through a wormhole and emerge into an alternative universe where the future is known in the past, because now this post appears in the list of search results.

  12. #12
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: How to convert int to char?

    Actually the link in Lykurg's post does not return this thread to me It does return a lot of results telling how to convert an int to a C string, though.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  13. #13
    Join Date
    Dec 2009
    Location
    New Orleans, Louisiana
    Posts
    791
    Thanks
    13
    Thanked 153 Times in 150 Posts
    Qt products
    Qt5
    Platforms
    MacOS X

    Default Re: How to convert int to char?

    Quote Originally Posted by Bong.Da.City View Post
    I have an integer and I want to convert it into char but keeping its value!! !!!

    How to do that?
    Unless I am misunderstanding what you want, I would suggest you look at QString::number.

Similar Threads

  1. Replies: 4
    Last Post: 30th April 2013, 00:49
  2. convert from QString to char[sizeof(...)]
    By adamatic in forum Qt Programming
    Replies: 4
    Last Post: 3rd September 2011, 09:05
  3. How to convert QString to std::string or char*?
    By yangyunzhao in forum Qt Programming
    Replies: 26
    Last Post: 26th August 2009, 06:52
  4. How to convert QString to char *
    By rajeshs in forum Qt Programming
    Replies: 7
    Last Post: 27th September 2007, 10:32
  5. How to convert wchar_t* into char*??
    By shailesh in forum Qt Programming
    Replies: 3
    Last Post: 22nd June 2006, 12:39

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.