By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,413 Members | 999 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,413 IT Pros & Developers. It's quick & easy.

calling ifstream from another class

P: 1
Hi guys,

I'm kind of new to C++. I encountered following problem. I would like to create a class from where i can read data from files. So implemented

FILEREADER.CPP:
#include "filereader.h"

#include <fstream>
#include <sstream>
#include <iostream>

using namespace std;

filereader::filereader()
{
}

filereader::~filereader()
{
}

bool filereader::readDataFromFile()
{
ifstream dataFile;
dataFile.open("testData.dat", ifstream::in);
if(!dataFile.is_open());
{
printf("Error: file could not be opened");
return false;
}
dataFile.close();
return true;
}

I call readDatafromFile() from MAIN.CPP, which looks like this:

#include "filereader.h"
#include <stdio.h>

int main(int argc, char **args)
{
filereader fr;
fr.readDataFromFile();
return 0;
}

But it won't work. It always tells me that i tcan't open the file. What am I doing wrong. Thanks for any help.

Regards
Steve
Nov 7 '06 #1
Share this question for a faster answer!
Share on Google+

Post your reply

Sign in to post your reply or Sign up for a free account.