以下是我的C++程序:
main.cpp中
#include <iostream>
#include <fstream>
using namespace std;
int main() {
ofstream fileWriter;
fileWriter.open ("firstFile.cpp");
fileWriter << "#include <iostream>" << endl;
fileWriter << "int main() {" << endl;
fileWriter << "\tstd::cout << \"hello world\" << std::endl;" << endl;
fileWriter << "\treturn 0;" << endl;
fileWriter << "}" << endl;
fileWriter.close();
return 0;
}
Run Code Online (Sandbox Code Playgroud)
执行上述程序时,它会创建一个名为"firstFile.cpp"的文本文件,其中包含以下代码:
firstFile.cpp
#include <iostream>
int main() {
std::cout << "hello world" << std::endl;
return 0;
}
Run Code Online (Sandbox Code Playgroud)
执行时,在屏幕上打印"hello world".
所以,我想在main.cpp文件中添加一行代码,要求GCC编译刚刚创建的新的firstFile.cpp.
我在平台Ubuntu和Windows上使用GNU gcc.
是否有可能从编译器调用中获取任何错误代码?如果没有原因.