0
#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

*/

Edited by happygeek: fixed formatting

2
Contributors
3
Replies
6
Views
9 Years
Discussion Span
Last Post by Duoas
0

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.

0

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.

0

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.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.