Hi guys,

I am having great difficulty in reading a text file char by char and storing them in a linked list.

I started off with simply attempting to read from file char by char, and that worked fine.

But when attempting to store the file into a linked list, it just doesnt seem to work.

Could someone please assist me with small sample code in regards to this. I have code written out and the error messages that im getting is as follows :

test11.cpp:79:16: warning: no newline at end of file
test11.cpp: In function 'int main(int, char**)':
test11.cpp:41: error: no matching function for call to 'std::basic_ifstream<char, std::char_traits<char> >::get(char [1])'
/opt/csw/gcc4/lib/gcc/sparc-sun-solaris2.8/4.0.2/../../../../include/c++/4.0.2/istream:272: note: candidates are: typename std::basic_istream<_CharT, _Traits>::int_type std::basic_istream<_CharT, _Traits>::get() [with _CharT = char, _Traits = std::char_traits<char>]
/opt/csw/gcc4/lib/gcc/sparc-sun-solaris2.8/4.0.2/../../../../include/c++/4.0.2/istream:286: note:                 std::basic_istream<_CharT, _Traits>& std::basic_istream<_CharT, _Traits>::get(_CharT&) [with _CharT = char, _Traits = std::char_traits<char>]
/opt/csw/gcc4/lib/gcc/sparc-sun-solaris2.8/4.0.2/../../../../include/c++/4.0.2/istream:313: note:                 std::basic_istream<_CharT, _Traits>& std::basic_istream<_CharT, _Traits>::get(_CharT*, std::streamsize, _CharT) [with _CharT = char, _Traits = std::char_traits<char>]
/opt/csw/gcc4/lib/gcc/sparc-sun-solaris2.8/4.0.2/../../../../include/c++/4.0.2/istream:324: note:                 std::basic_istream<_CharT, _Traits>& std::basic_istream<_CharT, _Traits>::get(_CharT*, std::streamsize) [with _CharT = char, _Traits = std::char_traits<char>]
/opt/csw/gcc4/lib/gcc/sparc-sun-solaris2.8/4.0.2/../../../../include/c++/4.0.2/istream:347: note:                 std::basic_istream<_CharT, _Traits>& std::basic_istream<_CharT, _Traits>::get(std::basic_streambuf<_CharT, _Traits>&, _CharT) [with _CharT = char, _Traits = std::char_traits<char>]
/opt/csw/gcc4/lib/gcc/sparc-sun-solaris2.8/4.0.2/../../../../include/c++/4.0.2/istream:357: note:                 std::basic_istream<_CharT, _Traits>& std::basic_istream<_CharT, _Traits>::get(std::basic_streambuf<_CharT, _Traits>&) [with _CharT = char, _Traits = std::char_traits<char>]

Please let me know if you want to see a snippet of my code, and i will post bit by bit

Looks like you are doing something like

ifstream ifs("foobar");
char chr[1];
// Read a char
ifs.get(chr);

Just change to plain char, i.e.

ifstream ifs("foobar");
char chr;
// Read a char
ifs.get(chr);
This article has been dead for over six months. Start a new discussion instead.