the uploaded is a assignment and i want to solve this task using the library fstream and using the tellp ,seekg other functions also can some body help me in that how to use all these things..!!I WROTE A FUNCTION ALSO BUT IT IS NOT READING THE FILE??? THE FUNCTION IS.--

#include "CSimpleList.h"


void CSimpleList::loadFromFile(string filename)
  if(filename == "")
      cout<<"Enter valid filename"<<endl;

  string line;
  ifstream myfile("Phonebook.txt",ios::in); 

  if (myfile.is_open())
      cout<<"file is opened"<<endl;
    while ( myfile.good() )
        cout<<"readin the line"<<endl;
      getline (myfile,line);
      cout << line << endl;
 else cout << "Unable to open file"; 


  int CSimpleList::size()
    return m_list.size();  

  int CSimpleList::getNumber(int pos)

    int i=m_pos;
    int number;
    string temp="";
    number=atoi(temp.c_str()); //convert string to integer
    return number;


Edited 3 Years Ago by Dani: Formatting fixed

Are you running this from inside the IDE?
If so, can you give it the full path to the file and see whhat happens?

the file that the program has to read has to be in a .txt format. you should also try declaring a variable using ofstream(used to put stuff in a text file), ifstream(used to output stuff thats in a text file), and fstream(works for both but has issues).

This article has been dead for over six months. Start a new discussion instead.