using namespace std;

class fileHandleString  {


ifstream infile;
ofstream outfile;


fileHandleString()  {

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


~fileHandleString() {



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


Recommended Answers

All 3 Replies

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.


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.

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.