Thread: unsetting setprecision

  1. #1
    Registered User
    Join Date
    Oct 2002
    Posts
    1

    unsetting setprecision

    I am currently trying to write a simple program that will perform various operations on two numbers inputted. I want the result to be formatted with a decimal point and a precision of 2. The program is an infinite loop until you actually quit. The problem I'm encountering is as follows:

    The first iteration of the program works fine. The numbers I input are displayed exactly as inputted and the result is formatted the way I want using << fixed << showpoint << setprecision(2). Subesequent iterations display the numbers inputted in the same format as the result, i.e. with decimal point and a precision of 2.

    Once I use fixed showpoint setprecision, how do I turn them off before the next iteration is performed?

  2. #2
    3 errors on line 112

    `fixed' undeclared (first use this function)

    (Each undeclared identifier is reported only once
    for each function it appears in.)

    `showpoint' undeclared (first use this function)

  3. #3
    Registered User
    Join Date
    Nov 2001
    Posts
    1,348
    Make sure you tell the compiler what functions you will use form the namespace standard.

    Code:
    using std::fixed;
    using std::showpoint;
    
    cin.setf(fixed | showpoint);
    cin.unsetf(fixed | showpoint);
    
    setiosflags(fixed | showpoint);
    resetiosflags(fixed | showpoint);
    
    long flag = cin.precision();
    cin.flags(flag);
    Kuphryn

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. setprecision()
    By hallo007 in forum C++ Programming
    Replies: 5
    Last Post: 11-25-2006, 09:38 AM
  2. setprecision??
    By rachael033 in forum C++ Programming
    Replies: 5
    Last Post: 03-22-2006, 02:33 AM
  3. setprecision() - can I count on it rounding or not?
    By major_small in forum C++ Programming
    Replies: 2
    Last Post: 11-23-2005, 02:26 PM
  4. setprecision()
    By OnionKnight in forum C++ Programming
    Replies: 2
    Last Post: 03-04-2005, 09:08 PM
  5. Setprecision
    By cerial-killer in forum C++ Programming
    Replies: 2
    Last Post: 03-30-2003, 12:02 PM