convert int to char

This is a discussion on convert int to char within the C++ Programming forums, part of the General Programming Boards category; hi, i've got to integers, lets say 0 and 6, which i want to copy into an character array. how ...

  1. #1
    Unregistered
    Guest

    convert int to char

    hi,
    i've got to integers, lets say 0 and 6, which i want to copy into an character array. how do i do this?

    char copied[3];
    //copied[0] should be 0
    //copied[1] should be 6
    //copied[2] should be '/0' - the terminating character.

    any suggestions?

    tom

  2. #2
    S­énior Member
    Join Date
    Jan 2002
    Posts
    982
    Code:
    #include <iostream> 
    #include <sstream> 
    using namespace std; 
    
    int main() 
    { 
    
    	stringstream ss;
    	int i=0;
    	int j=6;
    	char copied[3];
    	ss << i << j << '\0';
    	ss >> copied;
    	cout << copied;
    	return 0; 
    }

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 48
    Last Post: 09-26-2008, 03: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, 08:36 PM
  3. Replies: 8
    Last Post: 03-10-2008, 11:57 AM
  4. How do i un-SHA1 hash something..
    By willc0de4food in forum C Programming
    Replies: 4
    Last Post: 09-14-2005, 05:59 AM
  5. easy if you know how to use functions...
    By Unregistered in forum C Programming
    Replies: 7
    Last Post: 01-31-2002, 06:34 AM

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