944,093 Members | Top Members by Rank

Ad:
  • C++ Discussion Thread
  • Unsolved
  • Views: 4057
  • C++ RSS
Dec 4th, 2007
0

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

Expand Post »
#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

*/
Reputation Points: 10
Solved Threads: 0
Newbie Poster
ferrari77 is offline Offline
15 posts
since Dec 2007
Dec 4th, 2007
0

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

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.
Featured Poster
Reputation Points: 1140
Solved Threads: 229
Postaholic
Duoas is offline Offline
2,039 posts
since Oct 2007
Dec 4th, 2007
0

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

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.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
ferrari77 is offline Offline
15 posts
since Dec 2007
Dec 4th, 2007
0

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

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.
Featured Poster
Reputation Points: 1140
Solved Threads: 229
Postaholic
Duoas is offline Offline
2,039 posts
since Oct 2007

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C++ Forum Timeline: unknown error
Next Thread in C++ Forum Timeline: Labeling rows and columns in 2D arrays using enum type





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC