Thread: fstream errors

    #1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2003
    Posts
    64
    Rep Power
    12

    fstream errors


    This is the first time ive have errors doing fstream operations. I didnt do anything differnt than before.

    Errors:

    Code:
    In file included from main.cpp:20:
    functions.h: In member function `void Template::Top() const':
    functions.h:39: no matching function for call to `std::basic_ifstream<char,
       std::char_traits<char> >::basic_ifstream(std::string&)'
    /usr/include/c++/3.2.2/iosfwd:86: candidates are: std::basic_ifstream<char,
       std::char_traits<char> >::basic_ifstream(const std::basic_ifstream<char,
       std::char_traits<char> >&)
    /usr/include/c++/3.2.2/fstream:351:                 std::basic_ifstream<_CharT,
       _Traits>::basic_ifstream(const char*, std::_Ios_Openmode =
       std::ios_base::in) [with _CharT = char, _Traits = std::char_traits<char>]
    /usr/include/c++/3.2.2/fstream:338:                 std::basic_ifstream<_CharT,
       _Traits>::basic_ifstream() [with _CharT = char, _Traits =
       std::char_traits<char>]
    functions.h: In member function `void Template::Bottom() const':
    functions.h:47: no matching function for call to `std::basic_ifstream<char,
       std::char_traits<char> >::basic_ifstream(std::string&)'
    /usr/include/c++/3.2.2/iosfwd:86: candidates are: std::basic_ifstream<char,
       std::char_traits<char> >::basic_ifstream(const std::basic_ifstream<char,
       std::char_traits<char> >&)
    /usr/include/c++/3.2.2/fstream:351:                 std::basic_ifstream<_CharT,
       _Traits>::basic_ifstream(const char*, std::_Ios_Openmode =
       std::ios_base::in) [with _CharT = char, _Traits = std::char_traits<char>]
    /usr/include/c++/3.2.2/fstream:338:                 std::basic_ifstream<_CharT,
       _Traits>::basic_ifstream() [with _CharT = char, _Traits =
       std::char_traits<char>]
    functions.h: In member function `void Template::Middle() const':
    functions.h:55: no matching function for call to `std::basic_ifstream<char,
       std::char_traits<char> >::basic_ifstream(std::string&)'
    /usr/include/c++/3.2.2/iosfwd:86: candidates are: std::basic_ifstream<char,
       std::char_traits<char> >::basic_ifstream(const std::basic_ifstream<char,
       std::char_traits<char> >&)
    /usr/include/c++/3.2.2/fstream:351:                 std::basic_ifstream<_CharT,
       _Traits>::basic_ifstream(const char*, std::_Ios_Openmode =
       std::ios_base::in) [with _CharT = char, _Traits = std::char_traits<char>]
    /usr/include/c++/3.2.2/fstream:338:                 std::basic_ifstream<_CharT,
       _Traits>::basic_ifstream() [with _CharT = char, _Traits =
       std::char_traits<char>]
    My functions.h

    Code:
    #ifndef functions_h
    #define functions_h
    
    int doUpdate();
    int parse(const std::string& x);
    int topBox();
    int bottomBox();
    std::string templatepath = "home/projectlinux/templates";
    
    class Template
    {
    public:
      //constructors
      Template(){}
      ~Template(){}
      
      //accessors
      
      // methods
      void Top()const {
      	std::string temp;
            std::string topBit = "/home/projectlinux/public_html/templates/top.inc";
    	std::ifstream ifs(topBit);
    	while (!ifs.eof()) {
    	std::getline(ifs, temp);
    	std::cout << temp; } 
    	}
      void Bottom()const{
      	std::string temp;
    	std::string bottomBit = "/home/projectlinux/public_html/templates/bottom.inc";  
       	std::ifstream ifs(bottomBit);
    	while (!ifs.eof()) {
    	std::getline(ifs, temp);
    	std::cout << temp; }
      }
      void Middle()const{
      	std::string temp;
      	std::string sourceBit = "/home/projectlinux/public_html/news.inc";
    	std::ifstream ifs(sourceBit);
    	while (!ifs.eof()) {
    	topBox();
    	std::getline(ifs, temp);
    	std::cout << temp;
    	bottomBox();
    	}
    	}
    };
    
    int topBox() {
    
    std::string temp;
    std::string place = "/" + templatepath + "/topbox.inc";
    std::ifstream ifs(place.c_str());
    	while (!ifs.eof()) {
    	std::getline(ifs, temp);
    	std::cout << temp; } 
    	}
    	
    int bottomBox() {
    
    std::string temp;
    std::string place = "/" + templatepath + "/bottombox.inc";
    std::ifstream ifs(place.c_str());
    	while (!ifs.eof()) {
    	std::getline(ifs, temp);
    	std::cout << temp; } 
    	}  
      
    #endif
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2003
    Posts
    64
    Rep Power
    12
    Ok, i fell so damn dumb, just relised i was missing .c_str(). Moderator, please delete this thread.

IMN logo majestic logo threadwatch logo seochat tools logo