limits.h problem!!

This is a discussion on limits.h problem!! within the C++ Programming forums, part of the General Programming Boards category; Hello, A few weeks ago, I was asking about how to ignore a return after a cin (affected my getlines). ...

  1. #1
    Registered User
    Join Date
    Mar 2006
    Location
    USA::Colorado
    Posts
    155

    limits.h problem!!

    Hello,

    A few weeks ago, I was asking about how to ignore a return after a cin (affected my getlines). Now, I switched compilers, and have a serious issue:

    Code:
    main.cpp(38) : warning C4003: not enough actual parameters for macro 'max'
    main.cpp(38) : error C2589: '(' : illegal token on right side of '::'
    main.cpp(38) : error C2143: syntax error : missing ')' before '::'
    main.cpp(38) : error C2059: syntax error : ')'
    Here is the code

    Code:
    37: cin >> option;
    38: cin.ignore(numeric_limits<streamsize>::max(),'\n');
    39: return option;
    I'm using the 1998 version of Microsoft Visual C++ (if that helps at all).
    ~guitarist809~

  2. #2
    Just Lurking Dave_Sinkula's Avatar
    Join Date
    Oct 2002
    Posts
    5,006
    There is a difference between using <limits>, <limits.h>, and <climits> -- which is it that you are using?
    7. It is easier to write an incorrect program than understand a correct one.
    40. There are two ways to write error-free programs; only the third one works.*

  3. #3
    Registered User
    Join Date
    Jan 2005
    Posts
    7,317
    numeric_limits is in <limits>, and you should be using the std namespace for cin, numeric_limits and streamsize.

  4. #4
    Registered User
    Join Date
    Mar 2006
    Location
    USA::Colorado
    Posts
    155
    OK. heres the code (i used two limit files)
    Code:
    #include <iostream>
    #include <fstream>
    #include <math.h>
    #include <time.h>
    #include <iomanip>
    #include <conio.h>
    #include <string>
    #include <cmath>
    #include <cstdlib>
    #include <stdlib.h>
    #include <limits.h>
    #include <limits>
    #include <stdio.h>
    #include <cctype>
    #include <ctype.h>
    #include <cstdlib>
    #include <windows.h>
    
    using namespace std;
    bool checkFile(char filename[255])
    {
         ifstream check (filename);
         if (check)
            return 0;
         else
            return 1;
    }
    
    class movie
    {
            public:
            string title;
            string cat;
            string genre;
            movie *next;
    };
    
    int mainMenu()
    {
        int option;
        
        cout << "+-----------------------------+" << endl;
        cout << "|          MAIN MENU          |" << endl;
        cout << "+-----------------------------+" << endl <<
                "| 1. Enter a new movie        |" << endl << 
                "| 2. Show media               |" << endl <<
                "| 3. Search media             |" << endl << 
                "| 4. Help                     |" << endl << 
                "| 5. About                    |" << endl <<
                "| 6. Quit                     |" << endl <<
                "+-----------------------------+" << endl <<
                "|     :ENTER AN OPTION:       |" << endl <<
                "+-----------------------------+" << endl;
        cin >> option;
        cin.ignore(numeric_limits<streamsize>::max(),'\n');
        return option;
    }
    
    void decide(int opt, movie *head)
    {
         string title;
         string cat;
         string genre;
         int a = 0;
         ifstream check ("movie.ini");
         if (!check)
         {
                    a = 1;
         }
         check.close();
         
         if (opt == 1)
         {
                 cout << "Enter movie title: ";
                 getline(cin,title,'\n');
                 cout << "Enter movie category: ";
                 getline(cin,cat,'\n');
                 cout << "Enter movie genre: ";
                 getline(cin,genre,'\n');
    			 ofstream fOut ("movie.ini", ios::app);
                 if (a != 1)
                    fOut << endl;
                    
                 fOut << title << endl << cat << endl << genre;
                 fOut.close();
         }
         if (opt == 2)
         {
              int cnt = 1;
              movie *list;
              list = head;
              system("cls");
              cout << setw(3) << left << "#" << setw(40) << left << "Movie" <<  setw(17) << left << "Category" <<  setw(17) << left << "Genre\n" << endl;
              while (list != NULL)
              {
                    cout << setw(3) << left << cnt << setw(40) << left << list->title <<  setw(17) << left << list->cat <<  setw(17) << left << list->genre << endl;
                    list = list->next;
                    cnt++;
              }
         }
         if (opt == 4)
            cout << endl << endl << " -- Error opening help file!" << endl << endl;
         if (opt == 5)
            MessageBox(NULL,"(C) 1991-2006 Matt Nesterenko","About Media Manager",MB_OK);
         if (opt == 6)
            exit(0);
    }
    
    void menu(string menu, movie *head)
    {
         int opt;
         if (menu == "main")
            opt = mainMenu();
         decide(opt, head);
    }
    
    void orderInsert(movie *head, movie *mNode)
    {
         bool done = false;
         movie *prev;
         movie *curr;
    
         prev = curr = head;
         
         if (mNode->title <= head->title)
         {
              mNode->next=head;
              head=mNode;
         }
         else
         {
             while (curr != NULL && !done)
             {
                   if (mNode->title <= curr->title)
                   {
                        mNode->next = curr;
                        prev->next = mNode;
                        done = true;
                   }
                   prev = curr;
                   curr = curr->next;
             }
             if (!done)
                prev->next = mNode;
         }
    }
    
    int main (int argc, char *argv[])
    {
        movie *head;
        movie *mNode;
        movie *tail;
        
        char title[255], cat[255], genre[255];
    
        while (1)
        {
             ifstream input( "movie.ini");
             
             head = tail = NULL;
             
             if (input)
             {
                 while (input.getline(title, 255, '\n') &&
                        input.getline(cat, 255, '\n') &&
                        input.getline(genre, 255, '\n'))
                 {
                      mNode = new movie;
                      mNode->title = title;
                      mNode->cat = cat;
                      mNode->genre = genre;
                      mNode->next = NULL;
                      if (head == NULL)
                         head = mNode;
                      else
                      orderInsert(head,mNode);
                 }
             }
             menu("main", head);
             cout << endl << endl;
             system("pause");
             system("cls");
        }
        
        system("pause");
        return 0;
    }
    ~guitarist809~

  5. #5
    semi-colon generator ChaosEngine's Avatar
    Join Date
    Sep 2005
    Location
    Chch, NZ
    Posts
    597
    first get rid of whatever geriatric version of visual stuidio you're using. It's out of date and frankly, crap. You can get a shiny new version of visual C++ 2005 for free from msdn.

    Second, you're including <limits.h> and <limits>. Just use <limits>
    "I saw a sign that said 'Drink Canada Dry', so I started"
    -- Brendan Behan

    Free Compiler: Visual C++ 2005 Express
    If you program in C++, you need Boost. You should also know how to use the Standard Library (STL). Want to make games? After reading this, I don't like WxWidgets anymore. Want to add some scripting to your App?

  6. #6
    carry on JaWiB's Avatar
    Join Date
    Feb 2003
    Location
    Seattle, WA
    Posts
    1,972
    Code:
    #include <iostream>
    #include <fstream>
    #include <math.h>
    #include <time.h>
    #include <iomanip>
    #include <conio.h>
    #include <string>
    #include <cmath>
    #include <cstdlib>
    #include <stdlib.h>
    #include <limits.h>
    #include <limits>
    #include <stdio.h>
    #include <cctype>
    #include <ctype.h>
    #include <cstdlib>
    #include <windows.h>
    How can you possibly need so many headers? I don't think I've ever seen so many includes all in one chunk.

    First of all, drop all the .h headers (except possibly windows.h, but do you need that?) Then try to trim it down even more.
    "Think not but that I know these things; or think
    I know them not: not therefore am I short
    Of knowing what I ought."
    -John Milton, Paradise Regained (1671)

    "Work hard and it might happen."
    -XSquared

  7. #7
    Registered User
    Join Date
    Mar 2006
    Location
    USA::Colorado
    Posts
    155
    Actually, this is my includes.h file (for my c++ class) It has every include file that I can possibly use (except the limit problem)

    when you say drop the .h parts. I need conio.h (or is it just plain conio) ?
    ~guitarist809~

  8. #8
    Registered User
    Join Date
    Mar 2006
    Location
    USA::Colorado
    Posts
    155
    Quote Originally Posted by ChaosEngine
    first get rid of whatever geriatric version of visual stuidio you're using. It's out of date and frankly, crap. You can get a shiny new version of visual C++ 2005 for free from msdn.

    Second, you're including <limits.h> and <limits>. Just use <limits>
    Where can i get this "shiny new version?" (url)
    ~guitarist809~

  9. #9
    Guest Sebastiani's Avatar
    Join Date
    Aug 2001
    Location
    Waterloo, Texas
    Posts
    5,708
    another way to clear the stream is to use istream::seekg :

    Code:
    istream &
    flush(istream & is)
    {
    	is.clear();
    	is.seekg(ios::end);
    	return is;
    }
    
    int 
    main()
    {
    	int i;
    	do
    	{
    		flush(cin);
    		cout << "enter an integer:" << endl;
    		cin >> i;
    	}
    	while(cin.fail());
    }
    Code:
    #include <cmath>
    #include <complex>
    bool euler_flip(bool value)
    {
        return std::pow
        (
            std::complex<float>(std::exp(1.0)), 
            std::complex<float>(0, 1) 
            * std::complex<float>(std::atan(1.0)
            *(1 << (value + 2)))
        ).real() < 0;
    }

  10. #10
    Registered User
    Join Date
    Jan 2005
    Posts
    7,317
    The problem is probably due to the use of a macro for max that is included in visual C++ (probably in windows.h).

    Try adding #define NOMINMAX to the top of the file.

  11. #11
    Registered User
    Join Date
    Sep 2005
    Posts
    241
    Quote Originally Posted by guitarist809
    Actually, this is my includes.h file (for my c++ class) It has every include file that I can possibly use (except the limit problem)

    when you say drop the .h parts. I need conio.h (or is it just plain conio) ?
    I believe conio.h is included in windows.h or iostream, I could be wrong though...

  12. #12
    Registered User
    Join Date
    Mar 2006
    Location
    USA::Colorado
    Posts
    155
    Quote Originally Posted by Sebastiani
    another way to clear the stream is to use istream::seekg :

    Code:
    istream &
    flush(istream & is)
    {
    	is.clear();
    	is.seekg(ios::end);
    	return is;
    }
    
    int 
    main()
    {
    	int i;
    	do
    	{
    		flush(cin);
    		cout << "enter an integer:" << endl;
    		cin >> i;
    	}
    	while(cin.fail());
    }
    Thanks for the code, but I dont understand it.



    Also, I downloaded the Visual c++ Express from MSDN, I have 30 days to enter in a key I don't have AND it can't find the windows API (windows.h) or (windows)
    ~guitarist809~

  13. #13
    Registered User
    Join Date
    Mar 2006
    Location
    USA::Colorado
    Posts
    155
    Quote Originally Posted by bikr692002
    I believe conio.h is included in windows.h or iostream, I could be wrong though...
    I don't think it's included
    ~guitarist809~

  14. #14
    Registered User
    Join Date
    Sep 2005
    Posts
    241
    really?
    Oh wait, I'm thinking of stdlib.h or something like that

  15. #15
    Guest Sebastiani's Avatar
    Join Date
    Aug 2001
    Location
    Waterloo, Texas
    Posts
    5,708
    conio.h is a non-standard header for console manipulation (originally came with Borland compilers, I believe). at any rate, you can probably omit it since you aren't using any of its API.

    >> Thanks for the code, but I dont understand it.

    it simply clears the failure state of the stream and then seeks past whatever remains in its buffer.
    Code:
    #include <cmath>
    #include <complex>
    bool euler_flip(bool value)
    {
        return std::pow
        (
            std::complex<float>(std::exp(1.0)), 
            std::complex<float>(0, 1) 
            * std::complex<float>(std::atan(1.0)
            *(1 << (value + 2)))
        ).real() < 0;
    }

Page 1 of 2 12 LastLast
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Need help understanding a problem
    By dnguyen1022 in forum C++ Programming
    Replies: 2
    Last Post: 04-29-2009, 04:21 PM
  2. Memory problem with Borland C 3.1
    By AZ1699 in forum C Programming
    Replies: 16
    Last Post: 11-16-2007, 10:22 AM
  3. Someone having same problem with Code Block?
    By ofayto in forum C++ Programming
    Replies: 1
    Last Post: 07-12-2007, 08:38 AM
  4. A question related to strcmp
    By meili100 in forum C++ Programming
    Replies: 6
    Last Post: 07-07-2007, 02:51 PM
  5. WS_POPUP, continuation of old problem
    By blurrymadness in forum Windows Programming
    Replies: 1
    Last Post: 04-20-2007, 06:54 PM

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