Thread: Transforming Integers into Chars

  1. #1
    Registered User
    Join Date
    Dec 2001
    Posts
    10

    Transforming Integers into Chars

    I have a file IO where I read from file A.txt which contains an integer (int Bla).
    Later in the program, I want to save into a file, named after the integer in file A.txt, I
    write:

    strcat(Bla,".txt");

    ofstream w_file(Bla);
    w_file<<...;
    w_file.close();

    I know this doesn't work but what I want to know is how to make a char of in Bla, so that I can use it to save my file.
    Thanks!

  2. #2
    Registered User rmullen3's Avatar
    Join Date
    Nov 2001
    Posts
    330
    itoa()...

  3. #3
    ¡Amo fútbol!
    Join Date
    Dec 2001
    Posts
    2,138
    If you only need to use one digit integers, you can cast the char into an int. Then, subtract 48 from the int value. If the value is more than one int, you can use the same idea but it will be more complicated.

  4. #4
    Registered User
    Join Date
    Dec 2001
    Posts
    10

    Itoa...

    Thank you all very much!

    itoa didn't work, but that's because I'm using unix, so I found an unix-itoa on the web, when someone is interested, I'll post it.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Link List math
    By t014y in forum C Programming
    Replies: 17
    Last Post: 02-20-2009, 06:55 PM
  2. Assignment HELP!!
    By cprogrammer22 in forum C Programming
    Replies: 35
    Last Post: 01-24-2009, 02:24 PM
  3. Integers into array.
    By livestrng in forum C Programming
    Replies: 10
    Last Post: 10-29-2008, 11:35 PM
  4. Replies: 6
    Last Post: 08-04-2003, 10:57 AM
  5. fancy strcpy
    By heat511 in forum C++ Programming
    Replies: 34
    Last Post: 05-01-2002, 04:29 PM