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

Qt Code:
  1. #include <iostream>
  2. #include <string>
  3. #include <fstream>
  4. #include <QtGui>
  5.  
  6. using namespace std;
  7.  
  8.  
  9. class test {
  10.  
  11. private:
  12.  
  13.  
  14. public:
  15. ifstream myfile;
  16. bool open_file();
  17. void close_file();
  18. void next_question();
  19. };
  20.  
  21. bool open_file(){
  22.  
  23. myfile.open("C:\\test.txt");
  24. if(myfile.is_open()){
  25. qDebug() << "Open";
  26. return true;
  27. }
  28. else
  29. {
  30. qDebug() << "Error - file not opened";
  31. return false;
  32. }
  33. }
  34.  
  35. void close_file(){
  36.  
  37. myfile.close;
  38.  
  39. }
  40.  
  41.  
  42. void next_line(){
  43.  
  44. if(open_file()){
  45.  
  46. // Code here to do stuff with myfile
  47.  
  48. }
  49. else
  50. {
  51. qDebug() << "File not opened";
  52. }
  53.  
  54.  
  55. }
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