unsigned & macros in C++
Results 1 to 5 of 5

Thread: unsigned & macros in C++

  1. #1
    Junior Member
    Join Date
    Aug 2002
    Posts
    7

    unsigned & macros in C++

    well I'm back with more questions in C++....

    1. what exactly is a macro in C++?

    2. what is an "unsigned" type variable in C++?

    3. this one may seem even stupider, but in 3 C++ books I have yet to discover how: how do you store data from one program session for use in a later session?

    thnx

    btw it would be nice if anyone could give me the address of my previous C++ post, my browser freezes when I start a search......
    There are 10 types of people in this world, The ones that understand binary and the ones that dont.

  2. #2
    Senior Member
    Join Date
    Oct 2001
    Posts
    638
    1. what exactly is a macro in C++?
    It's the same as a macro in most languages. It's just a way of defining an operation that is used repetitively throughout a program.

    2. what is an "unsigned" type variable in C++?
    It's to do with how values are stored at the binary level. Unsigned means that the number is stored in ordinary binary format. Signed values use the highest bit to show the sign of the number. Obviously signed 1000 0001 will not have the same value as unsigned 1000 0001.

    3. this one may seem even stupider, but in 3 C++ books I have yet to discover how: how do you store data from one program session for use in a later session?
    Write the data to a file and read it back from the file when you need it again.
    OpenBSD - The proactively secure operating system.

  3. #3
    Senior Member
    Join Date
    Nov 2001
    Posts
    257
    To further ******** how you would keep data in a file.

    include the <fstream> header file, this includes the functions/classes you'll need to use file streams.

    do output information, declare an ofstream object:

    ofstream out_stream;

    then to open a file to write out to:

    out_stream.open("filename");

    and use the insertion operator:

    out_stream << strMyData.c_str() << endl;

    remember to out_stream.close() it when you're done.

    To read information back in, use an ifstream object:

    ifstream in_stream;
    in_stream.open("filename");

    and then employ the extraction operator:

    in_stream >> strMydata;

    and in_stream.close() it when you're done.

    Many more functions available in the library to fine tune the operations.
    -Shkuey
    Living life one line of error free code at a time.

  4. #4
    Senior Member
    Join Date
    Sep 2001
    Posts
    1,027
    signed vs unsigned:
    singed means the variable type can store negative or positive values.
    unsigned means it can only hold positive values.

    The way it works:
    An unsinged variable uses its whole memory space to to store values greater or equal to 0
    A signed varaible splits the variable memori space in two: half negative, half positive.

    Example:
    an int is stored on 4 bytes. the range of possible values is -32767 to 32767
    an unsigned int is also stored on 4 bytes, but the range of possible values is 0 to 65535

    Hope this helps...

    Ammo
    Credit travels up, blame travels down -- The Boss

  5. #5
    The Iceman Cometh
    Join Date
    Aug 2001
    Posts
    1,210
    They pretty much summed up #1 and #2 for you. #3, besides writing to a file, is OS dependent. For instance, in *nix, you can use a "pipe" to send the output of one program to be the input of another program. Works great. If you need it in Windows, it's a lottle more complicated, but doable if you know what you're doing... Once you have some more programming under your belt and become familiar with developing in whichever environment you plan to continue in, let me know and I can help you pipe the output to the ininput of another program.

    AJ

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •