Author Topic: "ofstream out" doesn't seem to be working, but cout << works ok  (Read 4911 times)

bobk544

  • Guest
"ofstream out" doesn't seem to be working, but cout << works ok
« on: December 23, 2007, 06:15:50 pm »
Hello, i'm wondering why the "out" statement is not showing up in the DOS command output window, ie when i run it just says:

Press ENTER to continue:

Thanks for any help!
BobK

Code
//: C11:HowMany.cpp
// A class that counts its objects
#include <fstream>
#include <string>
using namespace std;
ofstream out("HowMany.out");

class HowMany {
  static int objectCount;
public:
  HowMany() { objectCount++; }
  static void print(const string& msg = "") {
    if(msg.size() != 0) out << msg << ": ";
    out << "objectCount = "
         << objectCount << endl;
  }
  ~HowMany() {
    objectCount--;
    print("~HowMany()");
  }
};

int HowMany::objectCount = 0;

// Pass and return BY VALUE:
HowMany f(HowMany x) {
  x.print("x argument inside f()");
  return x;
}

int main() {
  HowMany h;
  HowMany::print("after construction of h");
  HowMany h2 = f(h);
  HowMany::print("after call to f()");
} ///:~

Offline killerbot

  • Administrator
  • Lives here!
  • *****
  • Posts: 5514
Re: "ofstream out" doesn't seem to be working, but cout << works ok
« Reply #1 on: December 23, 2007, 06:17:44 pm »
because you are writing to a file, not to cout !!


bobk544

  • Guest
Re: "ofstream out" doesn't seem to be working, but cout << works ok
« Reply #2 on: December 23, 2007, 06:22:14 pm »
oh ok thanks very much....duh :lol:

have some Happy Holidays!

bk