error: no matching function for call to 'getline(std::ofstream&, std::string&, char)'

Please support our C++ advertiser: Intel Parallel Studio Home
Reply

Join Date: Dec 2007
Posts: 4
Reputation: ferrari77 is an unknown quantity at this point 
Solved Threads: 0
ferrari77 ferrari77 is offline Offline
Newbie Poster

error: no matching function for call to 'getline(std::ofstream&, std::string&, char)'

 
0
  #1
Dec 4th, 2007
#include<string>
#include<iostream>
#include<fstream>


using namespace std;

class fileHandleString {

private:

ifstream infile;
ofstream outfile;

public:

fileHandleString() {

infile.open("input.txt", ios::in);
outfile.open("output.txt", ios::in);

}

~fileHandleString() {

infile.close();

}

string getFromFile() {

string str;
getline (outfile, str);
return (str);

}
};

/*The above code is what I am using but I keep getting the error found in the title. Any suggestions as I am at a loss. I've used getline plenty of times before but never really in conjunction with classes and files. Any assistance would be appreciated. Thanks.

-- Ferrari77

*/
Reply With Quote Quick reply to this message  
Join Date: Oct 2007
Posts: 1,953
Reputation: Duoas has much to be proud of Duoas has much to be proud of Duoas has much to be proud of Duoas has much to be proud of Duoas has much to be proud of Duoas has much to be proud of Duoas has much to be proud of Duoas has much to be proud of 
Solved Threads: 214
Featured Poster
Duoas's Avatar
Duoas Duoas is offline Offline
Posting Virtuoso

Re: error: no matching function for call to 'getline(std::ofstream&, std::string&, ch

 
0
  #2
Dec 4th, 2007
First, don't say ios::in. It is implied by the type of stream you are opening.

Second, getline() isn't defined on output files.

Hope this helps.
Reply With Quote Quick reply to this message  
Join Date: Dec 2007
Posts: 4
Reputation: ferrari77 is an unknown quantity at this point 
Solved Threads: 0
ferrari77 ferrari77 is offline Offline
Newbie Poster

Re: error: no matching function for call to 'getline(std::ofstream&, std::string&, char)'

 
0
  #3
Dec 4th, 2007
Duoas,

Thanks for your reply. But if I have to read a string in from an outfile what would you suggest?

-- Curtis Sumpter

ps. I realize this goes counter to the idea of an outfile but it is part of an assignment so the design of the program is not of my making. Thanks again.
Reply With Quote Quick reply to this message  
Join Date: Oct 2007
Posts: 1,953
Reputation: Duoas has much to be proud of Duoas has much to be proud of Duoas has much to be proud of Duoas has much to be proud of Duoas has much to be proud of Duoas has much to be proud of Duoas has much to be proud of Duoas has much to be proud of 
Solved Threads: 214
Featured Poster
Duoas's Avatar
Duoas Duoas is offline Offline
Posting Virtuoso

Re: error: no matching function for call to 'getline(std::ofstream&, std::string&, ch

 
0
  #4
Dec 4th, 2007
You can't read from an output file. Data goes out, not in. That's the whole point.

You can create a file that has both read and write access.
fstream inAndOut( "fooey.txt", ios::in | ios::out | ios::trunc );
But that's a different thing.

(BTW. I put that ios::trunc flag in there because you might find it handy when doing your homework. It causes the file to be overwritten every time you open it, so it operates like an output file, but with read access.)

Hope this helps.
Last edited by Duoas; Dec 4th, 2007 at 7:31 pm.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Other Threads in the C++ Forum
Thread Tools Search this Thread



Tag cloud for C++
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC