Frank

Frank

  • NA
  • 3
  • 0

Convert string to list_entry

May 22 2010 7:28 PM
I have a class for lists. It's template class that takes a type of list_entry:
class cSingleList<list_entry>

I have an insert function defined as such:
public void insert(int position, list_entry entry)

What insert does is it takes an int so that we can insert a value (list_entry entry) at a certain position (int position) in the list.

Finally, I have a function:

public void read_file_insert(string filepath)
        {
            // Pre: A filepath to a file that only has integers delimited by a newline
            // and a cSingleList obejct.
            // Post: Reads the file given by the filepath and then inserts the data
            // into a cSingleList object by calling its insert function.

            string line = "";
            int index = 0;
            TextReader fin = new StreamReader(filepath);

            while ((line = fin.ReadLine()) != null)
            {
                this.insert(index, line);
                index++;
            }
        }

What this does is it reads through a file that contains integers and then we call the insert function, passing it the position we want (index) and then the value (line).

However, I always get an error stating:
Argument '2': cannot convert type 'string' to type 'list_entry'.

How can I convert a string (line) to type list_entry?


Answers (2)