ios_base troubles

This is a discussion on ios_base troubles within the C++ Programming forums, part of the General Programming Boards category; I have some errors here that I do not know how to fix prbly somthing simple too Code: // prblm ...

  1. #1
    Registered User
    Join Date
    Apr 2002
    Posts
    95

    ios_base troubles

    I have some errors here that I do not know how to fix
    prbly somthing simple too

    Code:
    // prblm 3 pg 538 C++ Primer Plu
    // usestok2.cpp -o use the Stock class 
    #include <iostream>
    using namespace std;
    #include "stockh.hpp"
    
    const int STKS = 4; 
    
    int main()
    {
     // create an array of initialized objects 
       Stock stocks [STKS] = 
             {
              Stock ("NanoSmart", 12, 20.0),
              Stock("Boffo Objects", 200, 2.0), 
              Stock("Monolithic Obelisks", 130, 3.25), 
              Stock("Fleep Enterprises", 60, 6.5)
             };         
        
        cout.precision(2);	// #.## 
        //errors here
        cout.setf(ios_base::fixed, ios_base::floatfield);// #.## format
        cout.setf(ios_base::showpoint);	// #.## format
        
        cout << "Stock holdings :\n";
        int st;
        for (st=0;  st < STKS;  st++)
            cout << stocks[st];
        Stock top = stocks[0];
        for (st=1;  st < STKS;  st++)
            top = top.topval(stocks[st]);
            cout << "\nMost valuable holding:\n";
            cout << top;
        return 0;
    }
    here is the complier output
    Building Makefile: "C:\Dev-C++\Makefile.win"
    Executing make...
    make.exe all -f "C:\Dev-C++\Makefile.win"
    Execution terminated
    g++.exe -c stockm.cpp -o stockm.o -I"C:\Dev-C++\include" -I"C:\Dev-C++\include\g++-3" -I"C:\Dev-C++\include" -s
    stockm.cpp: In function `int main()':
    stockm.cpp:21: `ios_base' undeclared (first use this function)
    stockm.cpp:21: (Each undeclared identifier is reported only once
    stockm.cpp:21: for each function it appears in.)
    stockm.cpp:21: parse error before `::'
    stockm.cpp:22: parse error before `::'
    make.exe: *** [stockm.o] Error 1
    0

    please help!

  2. #2
    Registered User
    Join Date
    Apr 2002
    Posts
    52
    >>cout.setf(ios_base::fixed, ios_base::floatfield);// #.## format
    >> cout.setf(ios_base::showpoint); // #.## format

    Try this...
    Code:
    cout.setf(ios::fixed, ios::floatfield);
    cout.setf(ios::showpoint);
    cout << setprecision(3) // this will give you the #.## pt. precision
    Hope that helps.
    MS VC++ 6.0

  3. #3
    Registered User
    Join Date
    Apr 2002
    Posts
    95
    Thanks a gigabyte!
    I had to alter one line to get it working.
    cout.precision(2); // this will give you the #.## pt. precision

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 4
    Last Post: 01-15-2006, 05:14 AM
  2. Console-based file i/o troubles
    By Callith in forum C++ Programming
    Replies: 3
    Last Post: 12-25-2004, 09:22 PM
  3. sscanf troubles
    By williams75 in forum C Programming
    Replies: 5
    Last Post: 11-17-2002, 02:51 AM
  4. More Program Troubles...
    By face_master in forum Windows Programming
    Replies: 2
    Last Post: 08-01-2002, 06:40 AM
  5. having troubles
    By neandrake in forum C++ Programming
    Replies: 7
    Last Post: 03-07-2002, 09:31 PM

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