Thread: Const Char to Char Error

  1. #31
    VA National Guard The Brain's Avatar
    Join Date
    May 2004
    Location
    Manassas, VA USA
    Posts
    903
    The last few posts came up quick.. sometimes it's easy to overlook a new post
    • "Problem Solving C++, The Object of Programming" -Walter Savitch
    • "Data Structures and Other Objects using C++" -Walter Savitch
    • "Assembly Language for Intel-Based Computers" -Kip Irvine
    • "Programming Windows, 5th edition" -Charles Petzold
    • "Visual C++ MFC Programming by Example" -John E. Swanke
    • "Network Programming Windows" -Jones/Ohlund
    • "Sams Teach Yourself Game Programming in 24 Hours" -Michael Morrison
    • "Mathmatics for 3D Game Programming & Computer Graphics" -Eric Lengyel

  2. #32
    & the hat of GPL slaying Thantos's Avatar
    Join Date
    Sep 2001
    Posts
    5,681
    Quote Originally Posted by stickman
    I guess you guys just don't understand. I WANT IT TO RETURN AN INTEGER AND NOT A SYMBOL/CHARACTER. I tried itoa, returns symbol/character. I tried blah+=a, returns symbol/character. I want something that returns AN INTEGER. Let's do a test:

    #include <iostream>

    int main()
    {
    for (int x=0; x<10; x++)
    {
    char test;
    std::cout << "\nThe Number Is: ";
    std::cout << x;
    }
    std::cin.get();
    return 0;
    }

    That returns:

    The Number Is: 1
    The Number Is: 2
    The Number Is: 3
    The Number Is: 4
    The Number Is: 5
    The Number Is: 6
    The Number Is: 7
    The Number Is: 8
    The Number Is: 9

    Now, how do I save "The Number Is: x" to a string so I can use it later?

    P.S. Sorry if I'm going a little over edge, but nothing has been the correct output.
    A lot of wasted time can be saved by clearly stating what you want to do when you first post. Up until this point you never stated that you wanted to return an integer.

    Honestly I'm not sure you know what you want because you said Jawib's post is exactly what you wanted by that returns a string that contains the character representation of a number and not the number itself.

    Please in the future think about what it is exactly that you wish to accomplish before you start a new thread and then clearly communicate that in the orginal post.

  3. #33
    Registered User
    Join Date
    Aug 2004
    Posts
    193
    Quote Originally Posted by Thantos
    A lot of wasted time can be saved by clearly stating what you want to do when you first post. Up until this point you never stated that you wanted to return an integer.

    Honestly I'm not sure you know what you want because you said Jawib's post is exactly what you wanted by that returns a string that contains the character representation of a number and not the number itself.

    Please in the future think about what it is exactly that you wish to accomplish before you start a new thread and then clearly communicate that in the orginal post.
    I'm sorry for the misunderstanding. Jawib's post converts int a to string a and when you return string a it returns an integer and yes I have tried it several times.

  4. #34
    & the hat of GPL slaying Thantos's Avatar
    Join Date
    Sep 2001
    Posts
    5,681
    The function in Jawib's post returns a string not an integer. Just look at the name: IntToString or look at the return type: string

    What does that tell you?
    Last edited by Thantos; 08-29-2004 at 12:13 PM.

  5. #35
    Registered User
    Join Date
    Feb 2004
    Posts
    35
    If the numbers are only going to be unsigned single digits (0 to 9), there's a much simpler answer:
    Code:
    blah += '0' + a;
    If they are not, this method will bring much WeirdStuff™.

  6. #36
    Registered User
    Join Date
    Aug 2004
    Posts
    193
    Quote Originally Posted by Thantos
    The function in Jawib's post returns a string not an integer. Just look at the name: IntToString or look at the return type: string

    What does that tell you?
    But when the string is outputted, it outputs the int. Look at the FAQ page he posted. It says:


    /*
    * Program output:
    The int value is 5 and the string value is 5
    Paused, press Enter.
    *
    */

    "and the string value is 5" and I believe that 5 is an integer so when the string is outputted it outputs "5" and not the symbol for 5.

  7. #37
    & the hat of GPL slaying Thantos's Avatar
    Join Date
    Sep 2001
    Posts
    5,681
    Whenever you do output its as characters not as numbers. Say you have an int who's value is 12345. It prints the character 1, the character 2, the character 3, the character 4, and the character 5. cout has overloaded << operators which convert from whatever format into the individual characters that make that value.

    using Jawib's main function in his post:
    Code:
    int main()
    {
      std::string blah("Your number is: ");
      int num=1;
      blah+=IntToString(num);
    }
    blah gets the return from IntToString(). blah is a string. If it was an int you should be able to do
    Code:
    blah += 5;
    and have it work correctly.

    You can not rely sololy on cout to tell you what the type of a variable is.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Errors including <windows.h>
    By jw232 in forum Windows Programming
    Replies: 4
    Last Post: 07-29-2008, 01:29 PM
  2. Undefined Reference Compiling Error
    By AlakaAlaki in forum C++ Programming
    Replies: 1
    Last Post: 06-27-2008, 11:45 AM
  3. Quantum Random Bit Generator
    By shawnt in forum C++ Programming
    Replies: 62
    Last Post: 06-18-2008, 10:17 AM
  4. failure to import external C libraries in C++ project
    By nocturna_gr in forum C++ Programming
    Replies: 3
    Last Post: 12-02-2007, 03:49 PM
  5. Using VC Toolkit 2003
    By Noobwaker in forum Windows Programming
    Replies: 8
    Last Post: 03-13-2006, 07:33 AM