简体   繁体   English

编译器C ++中的fstream错误

[英]fstream error in compiler C++

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. fpin是一个文件,我已经检查了打开等情况。 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 . 您尝试调用的方法是std::fstream::get You can read about std::fstream here . 您可以在此处阅读有关std::fstream 信息

Well, the compiler is right, getc() is not a method on ifstream . 好吧,编译器是正确的, getc()不是ifstream的方法。 Here are your options: 这是您的选择:

http://en.cppreference.com/w/cpp/io/basic_ifstream 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. djechlin所说的,但是如果您想按字符获取,可以执行ch = fpin.get() ,它将抓取一个字符。 or you can do fpin >> ch; 或者你可以做fpin >> ch; to get a single character but ignore whitespace. 得到一个字符,但忽略空格。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM