Hi all I'm not too good at working with files, they confuse the hell out of me. However i have this class, let call it test.cpp
#include <iostream>
#include <string>
#include <fstream>
#include <QtGui>
using namespace std;
class test {
private:
public:
ifstream myfile;
bool open_file();
void close_file();
void next_question();
};
bool open_file(){
myfile.open("C:\\test.txt");
if(myfile.is_open()){
qDebug() << "Open";
return true;
}
else
{
qDebug() << "Error - file not opened";
return false;
}
}
void close_file(){
myfile.close;
}
void next_line(){
if(open_file()){
// Code here to do stuff with myfile
}
else
{
qDebug() << "File not opened";
}
}
#include <iostream>
#include <string>
#include <fstream>
#include <QtGui>
using namespace std;
class test {
private:
public:
ifstream myfile;
bool open_file();
void close_file();
void next_question();
};
bool open_file(){
myfile.open("C:\\test.txt");
if(myfile.is_open()){
qDebug() << "Open";
return true;
}
else
{
qDebug() << "Error - file not opened";
return false;
}
}
void close_file(){
myfile.close;
}
void next_line(){
if(open_file()){
// Code here to do stuff with myfile
}
else
{
qDebug() << "File not opened";
}
}
To copy to clipboard, switch view to plain text mode
The error i keep getting is:
" 'myfile' was not declared in this scope. "
How do i work with myfile across all of my functions within a class?
Thanks for your time and trouble
Bookmarks