unsetting setprecision

This is a discussion on unsetting setprecision within the C++ Programming forums, part of the General Programming Boards category; I am currently trying to write a simple program that will perform various operations on two numbers inputted. I want ...

  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?
    Attached Files Attached Files

  2. #2
    Banned Cgawd's Avatar
    Join Date
    Oct 2002
    Posts
    405
    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, 08:38 AM
  2. setprecision??
    By rachael033 in forum C++ Programming
    Replies: 5
    Last Post: 03-22-2006, 01: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, 01:26 PM
  4. setprecision()
    By OnionKnight in forum C++ Programming
    Replies: 2
    Last Post: 03-04-2005, 08:08 PM
  5. Setprecision
    By cerial-killer in forum C++ Programming
    Replies: 2
    Last Post: 03-30-2003, 11:02 AM

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