Apr 10, 2018 at 4:59pm UTC
Classes.cpp:
#include "Classes.h"
Car::Car()
{
}
int Car::GetYear()
{
return year;
}
int Car::GetSpeed()
{
return speed;
}
string Car::GetColor()
{
return color;
}
void Car::SetYear(int newYear)
{
year = newYear;
}
void Car::SetSpeed(int newSpeed)
{
speed = newSpeed;
}
void Car::SetColor(string newColor)
{
color = newColor;
}
void Car::Read(string filename)
{
string extra;
string word = " ";
Car words;
words.SetColor(" ");
ifstream file;
int i = 0;
cout << "Enter file name to read in." << endl;
cin >> filename;
file.open(filename);
if (file.is_open())
{
file >> words.GetColor;
}
}
Classes.cpp:
#ifndef CLASSES_H
#define CLASSES_H
#include <iostream>
#include <fstream>
#include <string>
#include "OtherClass.h"
using namespace std;
class Car
{
private: // Member varaibles
int year;
int speed;
string color;
public: // Member functions
int GetYear();
int GetSpeed();
string GetColor();
Car();
void SetYear(int newYear);
void SetSpeed(int newSpeed);
void SetColor(string newColor);
void Read(string filename);
};
#endif
Last edited on Apr 10, 2018 at 5:01pm UTC
Apr 10, 2018 at 5:00pm UTC
Hello Im new to this. Im having trouble trying to use set and get methods on an ifstream file for it to read. I would be pleased if someone could point me in the right dirction.