This is a real newbie question but my compiler is giving me the error:
std::fstream has no member named getc
It is relative to this line of code:
char ch;
for ((ch=fpin.getc());!fpin.eof();(ch=fpin.getc()))
fpin is a file and I have checked for opening etc. it's fine. I'm also not worried about the quality of the code, just worried about getting it to work. I've been staring at it so long that I can't see the problem.
The method you are trying to call is std::fstream::get
. You can read about std::fstream
here .
Well, the compiler is right, getc()
is not a method on ifstream
. Here are your options:
http://en.cppreference.com/w/cpp/io/basic_ifstream
usually
while(std::getline(myInStream, sstr))
{
// ...
}
is what you want.
What djechlin said, but if you do want to get by character you can do ch = fpin.get()
, which will grab a single character. or you can do fpin >> ch;
to get a single character but ignore whitespace.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.