Hello there, I am new to using classes, and have been having so many problems. I don't want to go to my teacher if I don't have to, because it is always my luck that it is something easy that I just overlooked somehow. I have been working on this for 3 days and I can't get it to read from a file.
#include <iostream>
#include "cMonthlyRainfall.h"
cMonthlyRainfall::cMonthlyRainfall()
{
}
void cMonthlyRainfall::set_values (cMonthlyRainfall &month, ifstream &fin)
{
int i;
for (i = 0; i < 12; i++)
{
fin >> month[i].rainfall;
fin >> month[i].hi_temp;
fin >> month[i].lo_temp;
month[i].average_temp = (month[i].hi_temp + month[i].lo_temp) / 2;
} //End for loop
} //End function set_values()
The errors that I am receiving are attached to that cpp file and the error codes are:
Code:
C:\Users\KingAroan\Desktop\CodeBlocks\Rainfall\cMonthlyRainfall.cpp||In member function 'void cMonthlyRainfall::set_values(cMonthlyRainfall&, std::ifstream&)':|
C:\Users\KingAroan\Desktop\CodeBlocks\Rainfall\cMonthlyRainfall.cpp|23|error: no match for 'operator[]' in 'month[i]'|
C:\Users\KingAroan\Desktop\CodeBlocks\Rainfall\cMonthlyRainfall.cpp|24|error: no match for 'operator[]' in 'month[i]'|
C:\Users\KingAroan\Desktop\CodeBlocks\Rainfall\cMonthlyRainfall.cpp|25|error: no match for 'operator[]' in 'month[i]'|
C:\Users\KingAroan\Desktop\CodeBlocks\Rainfall\cMonthlyRainfall.cpp|27|error: no match for 'operator[]' in 'month[i]'|
C:\Users\KingAroan\Desktop\CodeBlocks\Rainfall\cMonthlyRainfall.cpp|27|error: no match for 'operator[]' in 'month[i]'|
C:\Users\KingAroan\Desktop\CodeBlocks\Rainfall\cMonthlyRainfall.cpp|27|error: no match for 'operator[]' in 'month[i]'|
||=== Build finished: 6 errors, 0 warnings ===|
And finally here is my main.cpp file:
Code:
#include <iostream>
#include <fstream>
#include <iomanip>
#include "cMonthlyRainfall.h"
using namespace std;
int main()
{
ifstream fin;
int count;
cMonthlyRainfall month[12]; //Creates an object for each month
fin.open ("weather.dat");
if (!fin)
{
cout << "ERROR: Unable to find weather.dat";
return 1;
}
cMonthlyRainfall::set_values(month, fin)
return 0;
}
I am sure the errors are connected to the array but I am not sure since I haven't worked with a class before. I have been googling and reading the book but I can't figure it out. Thanks for any help.
Hi,
I've tried to use classes in my program, but the compiler simply gives an error on the word class . Am I the only one with this problem ? I have no idea how to use classes in c in linux environment(suse). If you've got any idea what should I do I would be very thankful.
Thanks to ya all !... (4 Replies)
im just trying to have some fun and kill some time writing a c++ program that has a person type in a car make and model then gives them a year and a price. or something like that. i always have problems getting it goin but once the ball is rolling im usually pretty good. anyone wanna help me out? ... (1 Reply)
I was wondering if I could put the section at the beginning rather than at the end before the definition of the class.
const REAL ModMisfit::DefMinDT = 0.01;
const REAL ModMisfit::DefSigma0 = 0.01;
const double ModMisfit::DefDAngSh = 2;
const REAL ModMisfit::DefKBeta = 5;... (2 Replies)
Hi, i have a question about C++. Is it possible to declare a class with a member ot the same class? For example, a linked list or i want to convert this C code to C++ class (Elemento)
typedef struct elemento
{
char name;
char value;
List<struct elemento> ltElementos;
... (7 Replies)
I have a file Map.hh shown below. I want to put the two classes Phase and Map in two different files Phase.hh and Map.hh. I have forward declaration before the Map class. How can I tackle this situation?
//////////////////////////////////////////////////////////////////////////
#ifndef... (3 Replies)
Hi,
I believe the next code is wrong:
class Egg {
Egg e;
int i;
Egg(int ii=0) : i(ii) {}
};
because you would end up with an endless definition (memory allocation) of Egg objects, thus int i.
Ok, so God Eckel proposes for a singleton:
class Egg {
static Egg e;
int... (5 Replies)
Hi all!
I am trying to register a device in an existing device class, but I am
having trouble getting the pointer to an existing class.
I can create a class in a module, get the pointer to it and then use
it to register the device with:
*cl = class_create(THIS_MODULE, className);... (0 Replies)
I have the two class definition as follows.
class A { public: int a; };
class B : virtual public A{ };
The size of class A is shown as 4, and size of class B is shown as 16. Why is this effect ?. (2 Replies)
Hello All,
I am a learner in C++. I was testing my inheritance knowledge with following piece of code.
#include <iostream>
using namespace std;
class base
{
public :
void display()
{
cout << "In base display()" << endl;
}
void display(int k)
{... (2 Replies)
Can anyone tell me if this is correct when creating classes in Java?
public abstract class Animal
{
public class Point
{
public int x,y;
}
public class Animal
{
protected Point loc;
protected String name;
protected Random rng;
String... (3 Replies)