1

当我尝试在 Unix 服务器上编译我的 C++ 代码时,我不断收到异常,但这些行只有:

#ifndef WEIGHTED_GRAPH_H
#endif

错误是:

In file included from Weighted_graph_tester.h:17,
                     from Weighted_graph_driver.cpp:18:
    Weighted_graph.h:1: error: stray â\357â in program
    Weighted_graph.h:1: error: stray â\273â in program
    Weighted_graph.h:1: error: stray â\277â in program
    Weighted_graph.h:1: error: stray â#â in program
    In file included from Weighted_graph_tester.h:17,
                     from Weighted_graph_driver.cpp:18:
    Weighted_graph.h:172:2: error: #endif without #if
    Weighted_graph.h:1: error: âifndefâ does not name a type

有任何想法吗?

4

1 回答 1

6

它告诉您文件中有以下字节:

Oct: 357 273 277
Hex: EF  BB  BF

这些是 UTF-8 编码文件中的字节顺序标记。显然,您的编译器不支持开头带有字节顺序标记的 UTF-8 源文件。事实上,在 UTF-8 文件中使用字节顺序标记甚至没有意义,因为任何单个单元的大小都只有一个字节。您应该确保在没有它的情况下保存文件。

来自 Unicode 标准:

Use of a BOM is neither required nor recommended for UTF-8, but may be encountered in contexts where UTF-8 data is converted from other encoding forms that use a BOM or where the BOM is used as a UTF-8 signature.

于 2013-04-07T19:45:17.170 回答