我有这个代码:
// basic file operations
#include <iostream>
#include <fstream>
using namespace std;
int main()
{
writeFile();
}
int writeFile ()
{
ofstream myfile;
myfile.open ("example.txt");
myfile << "Writing this to a file.\n";
myfile << "Writing this to a file.\n";
myfile << "Writing this to a file.\n";
myfile << "Writing this to a file.\n";
myfile.close();
return 0;
}
为什么这不起作用?它给了我错误:
1>------ Build started: Project: FileRead, Configuration: Debug Win32 ------
1> file.cpp
1>e:\documents and settings\row\my documents\visual studio 2010\projects\fileread\fileread\file.cpp(8): error C3861: 'writeFile': identifier not found
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
这只是一个简单的功能。我正在使用 Visual Studio 2010。
原文由 Master345 发布,翻译遵循 CC BY-SA 4.0 许可协议
函数声明 int writeFile() ;代码中似乎缺少。添加 int writeFile() ;在函数 main() 之前