来自fstream的未定义模板错误的隐式实例化

问题描述

考虑以下MWE

#include <fstream>
#include <string>
#include <iostream>
using namespace std;
 
int main () {
   char data[100];

   // open a file in write mode.
   ofstream outfile;
   outfile.open("/Users/DropBox/afile.dat");

   cout << "Writing to the file" << endl;
   cout << "Enter your name: ";
   cin.getline(data,100);

   // write inputted data into the file.
   outfile << data << endl;

   outfile.close();

   return 0;
}

这给了我Mac上Xcode上的很多“未定义模板的隐式实例化”错误。实际上,即使我删除了main函数内容,由于#include<fstream>,它仍然在fstream中给出以下错误

Return type of out-of-line deFinition of 'std::__1::basic_filebuf::setbuf' differs from that in the declaration

我的朋友在他的Xcode上运行了相同的代码,并且有效。 fstream库是否已损坏?你能告诉我如何解决这个问题吗?

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)