Originally Posted by
Salem
How exactly are you opening the files?
Are you using a relative or absolute path? If relative, where is 'home'?
What is the actual error message (or error number), we need more than "it doesn't work".
Maybe a few snippets of relevant code.
I'm opening the files using file I/O, i'll post the code, maybe it will be easier:
FileMgr.h:
Code:
#ifndef FileMgr_h /*inclusion guards*/
#define FileMgr_h
class FileMgr
{
public:
FileMgr(); /*Constructor*/
virtual ~FileMgr(); /*Virtual Destructor*/
void vSetFileName(char*); /*Function for setting the filename*/
void vClearFileNameBuffer(); /*Function for clearing the filename*/
char *cGetFileName() const; /*Function pointer to aqcuire the file name*/
void vReadFromFile(); /*Function for reading the contents of a file*/
protected:
char *m_cFilename; /*protected member variable*/
};
#endif
FileMgr.cpp
Code:
#include <iostream>
#include <fstream>
#include "FileMgr.h"
/*Function Definitions*/
FileMgr::FileMgr():m_cFilename(0) /*Constructor initialization list*/
{
}
FileMgr::~FileMgr() /*Destructor definition*/
{
m_cFilename = 0; /*Just incase we forget to clear the filename before the program ends*/
}
void FileMgr::vSetFileName(char *cFilename)
{
m_cFilename = cFilename; /*Assigns the contents of cFilename to m_cFilename*/
cFilename = 0; /*Assigns cFilename to NULL for safety*/
}
void FileMgr::vClearFileNameBuffer()
{
m_cFilename = 0; /*Assigns m_cFilename to NULL, so we can use it again*/
}
char *FileMgr::cGetFileName() const
{
return m_cFilename; /*Returns member variable to the program*/
}
void FileMgr::vReadFromFile()
{
char ch; /*Character for reading contents of file*/
std::ifstream iFile(m_cFilename); /*Create an ifstream object for opening a file for output*/
if(!iFile.is_open()) /*Checks if the file can be opened*/
{
std::cout << "Error! Unable to open " << m_cFilename << "..." << std::endl; /*If it can't, output this*/
}
else /*Otherwise...*/
{
while(iFile.get(ch)) /*Read the characters from the file*/
{
std::cout << ch; /*Output the file contents to the console*/
}
std::cout << std::endl; /*Output a new line to the console after file contents is read*/
}
iFile.close(); /*Close the file after it's purpose has bin fullfilled*/
}
This is my file manager system, hope this helps :S