【问题标题】:I keep getting clang: error: no input files in C++我不断收到clang:错误:C ++中没有输入文件
【发布时间】:2013-12-10 18:01:18
【问题描述】:

这是我的 C++ 代码:

#include <iostream>
#include <fstream>
#include <string>
using namespace std;

int main () {
    std::ifstream ifs ("strength_classes.txt", std::ifstream::in);

    char c = ifs.get();

    while (ifs.good()) {
        std::cout << c;
        c = ifs.get();
    }

    ifs.close();

    return 0;
}

然后我在教程中通过运行以下命令对其进行编译,但它输出错误:

Laptop:Downloads Stu$ c++ -c test.cpp
Laptop:Downloads Stu$ g++ -o test.o
clang: error: no input files

【问题讨论】:

  • 如果要使用std::,则无需使用using namespace std;
  • 我认为程序无法找到“strength_classes.txt”文件,所以没有提供“strength_classes.txt”,而是提供完整清晰的路径以便编译器找到
  • 仍然收到错误:(
  • @LiddleLaLoo 它不能解决问题。这只是与您的编码风格问题无关的评论。

标签: c++ file terminal ifstream


【解决方案1】:

我猜你正在尝试执行以下操作:

$ g++ test.cpp -c -o test.o
$ g++ test.o -o program

运行你的程序类型

$ ./program

之后。

【讨论】:

  • @LiddleLaLoo 不代表成功吗?
  • 为什么什么都不放?
  • @LiddleLaLoo 之后你应该有一个名为program 的可执行文件。您必须单独运行才能看到您的程序正常运行。
  • @LiddleLaLoo 这是正常行为。它创建了一个名为 program 的文件......你现在可以运行它:./program
【解决方案2】:
g++ -o test.o

这是错误的。 -o 标志应该指示生成的可执行文件的文件名,您不小心将其声明为 test.o,然后未能提供输入。

写:

g++ -o myBinary test.o

然后执行:

./myBinary

【讨论】:

    猜你喜欢
    • 2012-07-06
    • 2013-01-28
    • 1970-01-01
    • 2023-03-22
    • 2016-05-05
    • 1970-01-01
    • 2021-04-14
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多