【问题标题】:Why do I get "error C2006: '#include' : expected a filename, found 'identifier' "?为什么我会收到“错误 C2006: '#include' : expected a filename, found 'identifier'”?
【发布时间】:2011-04-14 03:48:53
【问题描述】:

我在 Visual C++ Express 2008 中的源代码如下:

#include “stdafx.h”
#include <iostream>
int _tmain(int argc, _TCHAR* argv[])
{
std::cout << “Hello world!\n”;
return 0;
} 

我正在使用 Ivor Horton 所著的 Visual C++ 2008 书

。这些是我遇到的错误。如何消除这些错误?

1>e:\my documents\visual studio 2008\projects\hello\hello\hello.cpp(1):错误 C2006:“#include”:需要一个文件名,找到“标识符”
1>e:\my documents\visual studio 2008\projects\hello\hello\hello.cpp(1) : 致命错误 C1083: 无法打开包含文件: '': 没有这样的文件或目录

谢谢!

【问题讨论】:

    标签: c++ visual-c++ header include compiler-errors


    【解决方案1】:

    使用双引号"stdafx.hHello world!\n 括起来

    目前你正在使用一些inverted quotes/quotation marks

    【讨论】:

    • 感谢您指出这一点,但我试过了,不幸的是它不起作用
    • 实际上是一个全新的集合:1>e:\my documents\visual studio 2008\projects\hello\hello\hello.cpp(2):警告 C4067:预处理器指令后出现意外标记 - 预期换行 1>e:\my documents\visual studio 2008\projects\hello\hello\hello.cpp(5) : error C2065: '“Hello' : undeclared identifier 1>e:\my documents\visual studio 2008\projects\你好\你好\hello.cpp(5):错误C2146:语法错误:缺少';'在标识符“世界”之前
    • and : 1>e:\my documents\visual studio 2008\projects\hello\hello\hello.cpp(5) : error C2065: 'world' : undeclared identifier 1>e:\my文档\visual studio 2008\projects\hello\hello\hello.cpp(5):错误 C2143:语法错误:缺少 ';'前 '!' 1>e:\my documents\visual studio 2008\projects\hello\hello\hello.cpp(5) : 错误 C2017: 非法转义序列 1>e:\my documents\visual studio 2008\projects\hello\hello\hello .cpp(5) : 错误 C2065: 'n"' : 未声明的标识符
    • @Anant:您还需要更改 Hello world!\n 周围的引号
    【解决方案2】:

    如果您直接从源代码复制代码示例,当编译器需要 ASCII 双引号 ( ASCII | 34 (hex : 22 | 八进制: 0042 | 二进制: 00100010) | Unicode | U+0022 (十进制: 34) )

    【讨论】:

      猜你喜欢
      • 2020-06-26
      • 1970-01-01
      • 1970-01-01
      • 2020-05-17
      • 1970-01-01
      • 1970-01-01
      • 2020-12-27
      • 2021-07-27
      • 2021-11-23
      相关资源
      最近更新 更多