printing ASCII

This is a discussion on printing ASCII within the C++ Programming forums, part of the General Programming Boards category; Hello, I'm wondering if there is a way to print the ASCII character when I have an ASCII value already. ...

  1. #1
    Unregistered
    Guest

    Question printing ASCII

    Hello,

    I'm wondering if there is a way to print the ASCII character when I have an ASCII value already.

    For example,

    Code:
    int value = 65;
    string character = function(65);
    is there any such a function, or similar function that will allow character = "A"?

    Thanks a lot!

  2. #2
    geek SilentStrike's Avatar
    Join Date
    Aug 2001
    Location
    NJ
    Posts
    1,141
    Code:
    #include <iostream>
    #include <string>
    
    int main() {
    	std::string blah;
    	blah += char(65);
    	std::cout << blah << std::endl;
    
    	return 0;
    }
    Prove you can code in C++ or C# at TopCoder, referrer rrenaud
    Read my livejournal

  3. #3
    Registered User
    Join Date
    Jul 2002
    Posts
    273
    a string class is overkill on this one (no offense silentstrike).

    Just do this:

    Code:
    std::cout << (char)65 << std::endl;
    This casts it to a char and cout will treat it as such.

  4. #4
    geek SilentStrike's Avatar
    Join Date
    Aug 2001
    Location
    NJ
    Posts
    1,141
    He seemed to want to use the character in a string. This is illegal, assuming function returns a char...

    string character = function(65);

    I intended to show both how to convert ascii value to a character, as well as how to put that character into a string.
    Prove you can code in C++ or C# at TopCoder, referrer rrenaud
    Read my livejournal

  5. #5
    Unregistered
    Guest
    thanks to both of you

    I really appreciate it......

    can i do the same when i want to convert from ascii character to ascii value?

  6. #6
    Unregistered
    Guest
    I figured it out ....

    thanks for your help and your patience with my beginner questions.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. C# Printing Problem
    By silverlight001 in forum C# Programming
    Replies: 0
    Last Post: 03-23-2009, 02:13 AM
  2. Replies: 11
    Last Post: 03-24-2006, 11:26 AM
  3. Trouble Printing ASCII Character
    By drdroid in forum C++ Programming
    Replies: 2
    Last Post: 04-27-2002, 09:04 PM
  4. Printing extended ASCII characters
    By Jonny M in forum C Programming
    Replies: 2
    Last Post: 03-01-2002, 10:12 AM
  5. Printing characters not in the ASCII table
    By Unregistered in forum C Programming
    Replies: 2
    Last Post: 01-21-2002, 01:47 PM

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