Results 1 to 8 of 8

Thread: structs

  1. #1

    Thread Starter
    <?="Moderator"?> john tindell's Avatar
    Join Date
    Jan 2002
    Location
    Brighton, UK
    Posts
    1,099

    structs

    Code:
    #include <iostream.h>
    
    struct database
    {
    	int USER_ID;
    };
    int main()
    
    {
    	database users;
    	users.USER_ID=110;
    		cout<<users.USER_ID;
    	return 0;
    }
    heres my code, now this out puts 110, but when ui change users.USER_ID to 0110 it outputs 72????

    im news to c++ so forgive me for the stupid question

    Thanks

  2. #2
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169

    Re: structs

    Firstly, <iostream>, not <iostream.h>

    As far as your numbers go, you've hit another intricacy inherited from C. When you give a number that begins with 0, it interprets it as Octal. I.e., 110 will be 110, but 0110 will be 110 octal, which is 72 decimal (check it on a calculator to see).
    I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
    -- Linus Torvalds

  3. #3

    Thread Starter
    <?="Moderator"?> john tindell's Avatar
    Join Date
    Jan 2002
    Location
    Brighton, UK
    Posts
    1,099
    wats an octal???

  4. #4
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    It's another number base. We have decimal (base 10, should be denary but hey ) which uses digits 0 to 9. Hexadecimal uses 0-9, A-F. Octal uses 0-7.
    I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
    -- Linus Torvalds

  5. #5

    Thread Starter
    <?="Moderator"?> john tindell's Avatar
    Join Date
    Jan 2002
    Location
    Brighton, UK
    Posts
    1,099
    gotya, o btw
    when i use

    #include <iostream>

    i get the error

    c:\C++\structures\source1.cpp(12): error C2065: 'cout' : undeclared identifier

    but i only get a warning when i use

    #include <iostream.h>

    c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\useoldio.h(29): warning C4995: '_OLD_IOSTREAMS_ARE_DEPRECATED': name was marked as #pragma deprecated

    ? any ideas about thats


    Thanks for the Help

  6. #6
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    Heh, the warning about the other one tells you enough: the old ones are deprecated.

    To use the new ones, they're all in the std namespace. So for simplicity, add a "using namespace std;" into the top of your source file, but after the includes.
    I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
    -- Linus Torvalds

  7. #7

    Thread Starter
    <?="Moderator"?> john tindell's Avatar
    Join Date
    Jan 2002
    Location
    Brighton, UK
    Posts
    1,099
    cheers

  8. #8
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    Nps
    I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
    -- Linus Torvalds

Posting Permissions

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



Click Here to Expand Forum to Full Width