Reputation: 1
I'm trying to use ifstream and ofstream to write/read in a header file but it doesn't work
`
#pragma once
#include<iostream>
#include<cmath>
#include<string>
#include<fstream>
using namespace std;
class Shape
{
protected:
ifstream ifs;
ofstream fout;
string name, color;
public:
Shape() { name = "no name"; color = "no color"; }
Shape(string n, string c) { name = n; color = c; }
virtual void readData()
{
cout << "enter the name" << endl;
cin >> name;
cout << "enter the color " << endl;
cin >> color;
}
virtual void print() { cout << "name =" << name << endl << "color =" << color << endl; }
//here is the error it said "this declartion has no storage class of type specifier
fout.open("shapeInfo.txt",ios::out)
};
`
I tried both ifstream and ofstream I changed it's place and it's name still the same it's work on the main tho but I need it in the header
Upvotes: 0
Views: 47