c++ - 非常基本的 C++ 错误

标签 c++ fstream

嘿伙计们,我正在写有史以来最简单的东西,只是创建一个 ifstream 来读取文本文件,但我遇到了一个奇怪的错误。这是代码(注意:iostream 和 fstream 缺少的 '<' 在我的代码中写得很好,但我不能在这里写)

#include "genlib.h"
#include "simpio.h"
#include "random.h"
#include "vector.h"
#include "map.h"
#include <iostream>
#include <fstream>

int main() {
 ifstream in;
 in.open("Hamlet.txt");
 if (in.fail()) Error("Could not open file");
 return 0;
}

我在 ifstream 中得到以下错误;行:“错误:'=' token 之前的预期不合格ID”

知道出了什么问题吗?

谢谢

最佳答案

ifstream in; 之后唯一不寻常的是 Error 调用。我的疯狂猜测是它是一个写得不好的宏。试试这个:

int main() {
 ifstream in;
 in.open("Hamlet.txt");
 if (in.fail()) { Error("Could not open file"); }
 return 0;
}

请注意 Error 周围的新大括号。

关于c++ - 非常基本的 C++ 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3804962/

相关文章:

c++ - 有人用过 Facebook Scribe 吗? (记录一切的工具)

c++ - 写入变量文件名

python - 这种逐行文件读取在 C++ 中怎么会比在 Python 中慢得多?

c++ - 如何将 fstream 读入 LPSAFEARRAY?

c++ - 如果一行包含某个 Word 保存它

javascript - 如何设置自定义 slider 的值

c++ - dlib 的 dcd trainer 的 'warm start' 选项是否只用于 1 类分类?

c++ - 错误 : argument of type ‘char (CharStack::)()const throw (CharStack::Underflow)’ does not match ‘char’

c++ - 带有文件流的 RAII

c++ - QLineEdit 绘制与实际文本不同的文本(文本()非空的占位符)