C:为什么找不到函数?

新手上路,请多包涵

我有这个代码:

 // 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 许可协议

阅读 350
1 个回答

函数声明 int writeFile() ;代码中似乎缺少。添加 int writeFile() ;在函数 main() 之前

原文由 Sumeet 发布,翻译遵循 CC BY-SA 3.0 许可协议

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题
logo
Stack Overflow 翻译
子站问答
访问
宣传栏