C++ 错误 - 编译 g++ 文件时“#include 需要“FILENAME”或 <FILENAME>”

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/12336573/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-27 16:10:59  来源:igfitidea点击:

Error - "#include expects "FILENAME" or <FILENAME>" while compiling g++ file

c++g++

提问by Singh

I'm quite new to Linux programming. I'm compiling a simple C++ code using g++:

我对 Linux 编程很陌生。我正在使用以下命令编译一个简单的 C++ 代码g++

#include“recip.hpp”
#include<cassert>

double recip (int i) {
// I should be non-zero.
assert (i != 0);
return 1.0/i;
}

The file recip.hppexists in my current directory. I don't understand why I'm getting an error:

该文件recip.hpp存在于我的当前目录中。我不明白为什么我收到错误:

recip.cpp:1:9: error: #include expects "FILENAME" or <FILENAME>

What's wrong?

怎么了?

回答by

The compiler is not a text editor, nor a human - it checks for exact character code match, not for visual similarity... You have to use

编译器不是文本编辑器,也不是人类 - 它会检查字符代码是否完全匹配,而不是视觉相似性......你必须使用

#include "recip.hpp"

using the standard double quotation marks.

使用标准的双引号。

回答by Jonathan Leffler

Your first line, treated as UTF-8, reads:

您的第一行被视为 UTF-8,内容如下:

0x23 = U+0023
0x69 = U+0069
0x6E = U+006E
0x63 = U+0063
0x6C = U+006C
0x75 = U+0075
0x64 = U+0064
0x65 = U+0065
0xE2 0x80 0x9C = U+201C
0x72 = U+0072
0x65 = U+0065
0x63 = U+0063
0x69 = U+0069
0x70 = U+0070
0x2E = U+002E
0x68 = U+0068
0x70 = U+0070
0x70 = U+0070
0xE2 0x80 0x9D = U+201D
0x0A = U+000A

The U+201C and U+201D need to be replaced by U+0022 (ASCII 34), or ".

U+201C 和 U+201D 需要替换为 U+0022 (ASCII 34) 或"

MS Word and other word processors make bad editors for C code.

MS Word 和其他文字处理器为 C 代码编写了糟糕的编辑器。

回答by 22too

start swig when wei build example.i.

当wei构建example.i时开始swig。

example_wrap.c:2948:10: error: #include expects "FILENAME" or

example_wrap.c:2948:10: 错误:#include 需要“FILENAME”或

/* File: example.i */
%module example
%{
#define SWIG_FILE_WITH_INIT
#include 'example.h'
%}
int fact(int n);

we change code :

我们更改代码:

/* File: example.i */
%module example

%{ 
#define SWIG_FILE_WITH_INIT
#include "example.h"
%}
int fact(int n); 

it is just in include 'double quote'.

它只是包含“双引号”。