| | |
error: no matching function for call to 'getline(std::ofstream&, std::string&, char)'
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Dec 2007
Posts: 4
Reputation:
Solved Threads: 0
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
*/
#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
*/
Re: error: no matching function for call to 'getline(std::ofstream&, std::string&, ch
0
#2 Dec 4th, 2007
•
•
Join Date: Dec 2007
Posts: 4
Reputation:
Solved Threads: 0
Re: error: no matching function for call to 'getline(std::ofstream&, std::string&, char)'
0
#3 Dec 4th, 2007
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.
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.
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.
![]() |
Other Threads in the C++ Forum
- Previous Thread: unknown error
- Next Thread: Labeling rows and columns in 2D arrays using enum type
| Thread Tools | Search this Thread |
Tag cloud for C++
api application array arrays based beginner binary bmp c++ c/c++ calculator char char* class classes code coding compile compiler console conversion convert count data database delete deploy developer dll dynamiccharacterarray email encryption error file format forms fstream function functions game generator givemetehcodez graph gui homeworkhelp iamthwee ifstream image input int java lib list loop looping loops map math matrix memory multiple newbie news number numbertoword output pointer problem program programming project python random read recursion recursive reference rpg simple sorting string strings temperature template templates text text-file tree url variable vector video visual visualstudio void win32 windows winsock wordfrequency wxwidgets






