invalid conversion from `char*' to `char'

I dont want to show too much of the coding as this is an assignment. Anyways what I want to do is read into a text file and obtain what is written and lets just say for now it is text. I want to take in all the space characters etc also therefore I used getline() but the problem for me now is that I need break the line into characters so I can store it into a linked list. Below is my code which allows me to break the line down but my next task is to store each character including the space character into a linked list and here is when I get the error invalid conversion from `char*' to `char'.

I kind of understand why it is throwing that error but i don't know how to fix it. myList is just a STD linked list template where maze is a class that I have created which stores char.

Any help will much appreciated. Thanks

void fillList(list<maze> &myList, char *file)
{
string blocks;
ifstream ins(file);
while (getline (ins,blocks)) {
/*
characters taken from file need to be in
string form to include spacing to retain formatting.
This section will convert to char to store into list
*/
char *t, *c_input, y;
c_input = new char [blocks.size()+1];
strcpy (c_input,blocks.c_str());
t = strtok(c_input,"\n");
myList.push_back(t);
}
maze is a class that I have created which stores char.
myList.push_back(t);

myList is of type maze, but you are trying to push a char* into it.

Does your maze class have a constructor that takes a char* as it's initializer? If so, you could do something like:

myList.push_back(maze(t));
Hi JRaskell

Thanks for that. I had to alter the class to take in char* and added the extra brackets to the push_back line. Anwyays it works now and is doing what it is meant to be doing.

Thanks again.
Topic archived. No new replies allowed.