Rob Stainforth
Rob Stainforth

Reputation: 11

Missing <ofstream>: No such file or Directory

Running Ubuntu 12.04, using the g++ compiler and have the essential-build installed. Currently trying to get a small little program to work the code is below:

#include "Muon.h"
#include "Electron.h"
#include "Photon.h"


#include <string>
using std::string;

#include <iostream>
using std::cout;
using std::cin;
using std::endl;

#include <ofstream>
using std::ofstream;
#include <vector>
using std::vector;

using namespace std;
int main(){
  cout << "Let's create a Particle vector!" << endl;
  Electron* a = new Electron(10.0,20.0,30.0);
  cout << "Electron created" << endl;

  Muon* b = new Muon(30.0,20.0,10.0);
  cout << "Muon created" << endl;

  Photon* c = new Photon(20.0,10.0,30.0);
  cout << "Photon created" << endl;

  vector<Particle*> particlesContainer;
  particlesContainer.push_back(a);
  particlesContainer.push_back(b);
  particlesContainer.push_back(c);
  int size = particlesContainer.size();
  cout << "size is: " << size << endl;

  ofstream file("Muon_Vector.data");
  if (file.is_open()){
    for (int i = 0; i < size; i++){
      file << particlesContainer[0]->getType << endl;
    }
  }
  else {cout << "Unable to open file" << endl;}
  file.close();
  return 0;
}

Upon trying to compile I receive the error:

"intParticles.cpp:15:20: fatal error: ofstream: No such file or directory compilation terminated."

This is after typing: "g++ -Wall Particle.cpp intParticles.cpp -o run"

Any help as to what is going wrong would be grateful. I thought ofstream was part of the standard library?

Upvotes: 1

Views: 4565

Answers (1)

user470988
user470988

Reputation:

ofsteam is class but not the header file. It is defined in 'fstream' file

Upvotes: 4

Related Questions