integer to short

This is a discussion on integer to short within the C++ Programming forums, part of the General Programming Boards category; Hello. I'm still working on my Huge_Int project, but have run into another snag. I'm not looking for code, but ...

  1. #1
    essence of digital xddxogm3's Avatar
    Join Date
    Sep 2003
    Posts
    589

    Arrow ??integer too small for my needs or is it??

    Hello.

    I'm still working on my Huge_Int project, but have run into another snag.

    I'm not looking for code, but would like a little more assistance.

    I'm inputing data into an integer.

    Code:
    int x=0;
    
    cin>>x;
    
    cout<<x;
    Above is the basics, but when I input an integer like
    9876543212
    I get
    2147483647
    From what I've read my max size available is 2,147,483,648
    I have tried to change it to a unsigned long int, but it causes some of the same errors.

    How can I rig a work around?

    Thanks in advanced for any assistance.
    Last edited by xviddivxoggmp3; 09-24-2003 at 12:09 AM.
    "Hence to fight and conquer in all your battles is not supreme excellence;
    supreme excellence consists in breaking the enemy's resistance without fighting."
    Art of War Sun Tzu

  2. #2
    lyx
    lyx is offline
    Amateur
    Join Date
    Sep 2003
    Posts
    228
    Yes, it is the limit of an integer (int).
    But sorry I don't know how you could make it work. The only way I'm thinking of is to write your own input string to integer function which will return either a structure made of as much fields as you like or a long long (__int64 for some compilers).

  3. #3
    essence of digital xddxogm3's Avatar
    Join Date
    Sep 2003
    Posts
    589

    __int64

    I tried to use __int64, but no luck.

    Code:
     
    __int64 Buffer1=0;
    
    cin>>Buffer1;
    i get this error:

    error C2679: binary '>>' : no operator found which takes a right-hand operand of type '__int64' (or there is no acceptable conversion)
    "Hence to fight and conquer in all your battles is not supreme excellence;
    supreme excellence consists in breaking the enemy's resistance without fighting."
    Art of War Sun Tzu

  4. #4
    lyx
    lyx is offline
    Amateur
    Join Date
    Sep 2003
    Posts
    228
    Yes, I knew, but what I was saying is that you should create your own input-string to integer functionk, that is, overload the operator for it to take a 64-bit-integer.

  5. #5
    essence of digital xddxogm3's Avatar
    Join Date
    Sep 2003
    Posts
    589
    Sorry I haven't become comfortable with operater overloading yet.
    I'm not sure how I would get it to work in my program. Could you recomend a good tutorial to review on the subject?
    Last edited by xviddivxoggmp3; 09-24-2003 at 02:47 AM.
    "Hence to fight and conquer in all your battles is not supreme excellence;
    supreme excellence consists in breaking the enemy's resistance without fighting."
    Art of War Sun Tzu

  6. #6
    essence of digital xddxogm3's Avatar
    Join Date
    Sep 2003
    Posts
    589
    sorry to repost, but lyx are you still online?
    Do you know of a location with an indepth tutorial of some kind on operater overloading? It has to be basic for a newbie.
    "Hence to fight and conquer in all your battles is not supreme excellence;
    supreme excellence consists in breaking the enemy's resistance without fighting."
    Art of War Sun Tzu

  7. #7
    lyx
    lyx is offline
    Amateur
    Join Date
    Sep 2003
    Posts
    228
    Sorry, but this morning (because it was morning here) I was very late at school so I didn't have the time to disconnect...

    Well, I only know of French tutorials as I'm French...

    [EDIT]I've just realized, it's odd that the forum does not log us out when we quit the site.
    Last edited by lyx; 09-24-2003 at 04:32 AM.

  8. #8
    Registered User
    Join Date
    Mar 2002
    Posts
    1,595
    you can look at this site for operator overloading information:

    http://www.icce.rug.nl/documents/cpl...us09.html#l138

  9. #9
    Registered User
    Join Date
    Jan 2002
    Location
    Vancouver
    Posts
    2,220
    Code:
    #include <climits>
    
    ...
    
    long long foo = LONG_LONG_MAX;
    cout << foo;
    or if you never need to go below 0...
    Code:
    #include <climits>
    
    ...
    
    unsigned long long bar = ULONG_LONG_MAX;
    cout << bar;
    Last edited by Brian; 09-24-2003 at 10:09 AM.

  10. #10
    essence of digital xddxogm3's Avatar
    Join Date
    Sep 2003
    Posts
    589

    Arrow long long

    lyx, sorry about that. I was just wondering .

    Elad, thanks for the link I will review those details now.

    Brian,
    My compiler doesn't recognize a long long.
    i'm using microsoft c++.net
    i've read about it, but have been unable to find anything about long long needing a header file. My experimentation with the long long have been completely unsuccessful.
    is there a header file needed for the long long?
    Last edited by xviddivxoggmp3; 09-24-2003 at 07:01 PM.
    "Hence to fight and conquer in all your battles is not supreme excellence;
    supreme excellence consists in breaking the enemy's resistance without fighting."
    Art of War Sun Tzu

  11. #11
    lyx
    lyx is offline
    Amateur
    Join Date
    Sep 2003
    Posts
    228
    long long is part of the standard I think, however, MSVC did never recognize it, so, instead, use __int64, it's the same.

  12. #12
    Cat
    Cat is offline
    Registered User
    Join Date
    May 2003
    Posts
    1,571
    Originally posted by lyx
    long long is part of the standard I think, however, MSVC did never recognize it, so, instead, use __int64, it's the same.
    long long is in the C99 standard, not the C++98 standard. So it's standard C (albeit only with C99 compilers), but it's nonstandard in C++ at this time.
    You ever try a pink golf ball, Wally? Why, the wind shear on a pink ball alone can take the head clean off a 90 pound midget at 300 yards.

  13. #13
    lyx
    lyx is offline
    Amateur
    Join Date
    Sep 2003
    Posts
    228
    Well, I just cannot afford to buy a copy of the standards as I don't have any money left. The fact is that compilers costs really a lot and so do books, so, even with all anniversary and christmas things...

    But, could you tell me why does C99 includes that much features that ISO-C++ just don't know?

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. memory issue
    By t014y in forum C Programming
    Replies: 2
    Last Post: 02-21-2009, 12:37 AM
  2. Link List math
    By t014y in forum C Programming
    Replies: 17
    Last Post: 02-20-2009, 06:55 PM
  3. Looking for constructive criticism
    By wd_kendrick in forum C Programming
    Replies: 16
    Last Post: 05-28-2008, 10:42 AM
  4. load gif into program
    By willc0de4food in forum Windows Programming
    Replies: 14
    Last Post: 01-11-2006, 10:43 AM
  5. Color Variety
    By Unregistered in forum C++ Programming
    Replies: 7
    Last Post: 10-23-2002, 10:17 AM

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