int to char

This is a discussion on int to char within the C++ Programming forums, part of the General Programming Boards category; Ok i got a simple question how do you change a int to char...

  1. #1
    Registered User
    Join Date
    Nov 2006
    Posts
    7

    int to char

    Ok i got a simple question
    how do you change a int to char

  2. #2
    Registered User
    Join Date
    Dec 2005
    Location
    Canada
    Posts
    267
    itoa()

    search MSDN for it

  3. #3
    Just Lurking Dave_Sinkula's Avatar
    Join Date
    Oct 2002
    Posts
    5,006
    Quote Originally Posted by Afan
    Ok i got a simple question
    how do you change a int to char
    Do you mean a string -- a C++ string?
    FAQ > How do I... (Level 1) > Convert a string to a int (C++)
    Quote Originally Posted by h_howee
    itoa()
    sprintf is standard (or stringstreams).
    7. It is easier to write an incorrect program than understand a correct one.
    40. There are two ways to write error-free programs; only the third one works.*

  4. #4
    Registered User
    Join Date
    Dec 2005
    Location
    Canada
    Posts
    267
    typecasting if u did want int to char

  5. #5
    Registered User IdioticCreation's Avatar
    Join Date
    Nov 2006
    Location
    Lurking about
    Posts
    229
    I don't know if it's proper, but I like stringstream. Something like this:

    Code:
    #include <sstream>
    
    int x = 3;
    std::stringstream s;
    //streams x into the string
    s << x;
    //function to call s is s.str()
    cout<< s.str();
    Last edited by IdioticCreation; 11-27-2006 at 10:14 PM.

  6. #6
    Registered User
    Join Date
    Nov 2006
    Posts
    7
    Quote Originally Posted by h_howee
    itoa()

    search MSDN for it
    Code:
    itoa(Value, Combo01_String*, 10);
    c:\Documents and Settings\David Brotz\My Documents\Visual Studio Projects\MathChecker 2.0\MathChecker 2.0Dlg.cpp(22): error C2143: syntax error : missing ';' before '.'

    For the FAQ one, i dont really understand how it converts so id rather do something i understand.

  7. #7
    Just Lurking Dave_Sinkula's Avatar
    Join Date
    Oct 2002
    Posts
    5,006
    Quote Originally Posted by Afan
    Code:
    itoa(Value, Combo01_String*, 10);
    c:\Documents and Settings\David Brotz\My Documents\Visual Studio Projects\MathChecker 2.0\MathChecker 2.0Dlg.cpp(22): error C2143: syntax error : missing ';' before '.'
    Is that a type and not a value? Why not sprintf?
    7. It is easier to write an incorrect program than understand a correct one.
    40. There are two ways to write error-free programs; only the third one works.*

  8. #8
    Registered User
    Join Date
    Dec 2005
    Location
    Canada
    Posts
    267
    maybe you should go with sprintf instead. Daves a better at this than i am

  9. #9
    Registered User whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    7,752
    Program on an eight bit platform. int and char should be the same there.

  10. #10
    Just Lurking Dave_Sinkula's Avatar
    Join Date
    Oct 2002
    Posts
    5,006
    Quote Originally Posted by citizen
    Program on an eight bit platform. int and char should be the same there.
    There I would especially doubt it.
    7. It is easier to write an incorrect program than understand a correct one.
    40. There are two ways to write error-free programs; only the third one works.*

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 48
    Last Post: 09-26-2008, 04:45 AM
  2. can some one please tell me the cause of the error ?
    By broli86 in forum C Programming
    Replies: 8
    Last Post: 06-26-2008, 09:36 PM
  3. Replies: 14
    Last Post: 06-28-2006, 02:58 AM
  4. Game Won't Compile
    By jothesmo in forum C++ Programming
    Replies: 2
    Last Post: 04-01-2006, 04:24 PM
  5. Contest Results - May 27, 2002
    By ygfperson in forum A Brief History of Cprogramming.com
    Replies: 18
    Last Post: 06-18-2002, 02:27 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21