Thread: cout char is a number

  1. #1
    Registered User
    Join Date
    May 2011
    Posts
    8

    cout char is a number

    Hi all, I'm trying to print off a grid system in c++.

    My problem is that whenever i try to add to the ascii number it prints off as a number instead of the letter/symbol

    Here is a snippit of my code
    Code:
    char start = 'a'
    
            if(j>=2){
                cout << (char)start+1;
                start++;
            }
    As you can see I'm tried casting, doesn't work.

    In addition the start++ doesn't work.

    Thank you in advanced.


  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    Try (char)(start + 1). Actually, it would be easier to just print start and let the start++ do its work for the next iteration.

    Wait, there is no loop. So perhaps you should increment start before printing; I don't know what exactly you want to do.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  3. #3
    Registered User
    Join Date
    May 2011
    Posts
    8
    Ah thank you. I figured why start++ wasn't working.

    I needed to make start a static char.

    Thank you anyway.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. char* value to Hex number
    By Notneo in forum C++ Programming
    Replies: 2
    Last Post: 04-09-2011, 10:11 PM
  2. Replies: 6
    Last Post: 07-15-2008, 02:27 PM
  3. Append certain number of characters to char[]?
    By Queue in forum C Programming
    Replies: 14
    Last Post: 09-16-2006, 08:39 PM
  4. How to print the value of char pointers using cout?
    By Antigloss in forum C++ Programming
    Replies: 7
    Last Post: 09-21-2005, 04:56 PM
  5. char number to same int number
    By Unregistered in forum C++ Programming
    Replies: 6
    Last Post: 07-18-2002, 05:22 PM