ofstream错误在c ++ [英] ofstream error in c++

查看:1839
本文介绍了ofstream错误在c ++的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在C ++中遇到一个流错误,这里是我的代码

  int main(){
ofstream myfile;
myfile.open(example.txt);
myfile<< 将此文件写入file.\\\
;
myfile.close();
return 0;
}



Dev-C ++ 10中的

错误


C:\devp\main.cpp aggregate
`std :: ofstream OutStream'有
不完整类型,不能定义

$提前感谢

解决方案

您可以试试这个:

  #include< fstream& 
using namespace std;

int main(){
ofstream myfile;
myfile.open(example.txt);
myfile<< 将此文件写入file.\\\
;
myfile.close();
return 0;
}


I am getting an ofstream error in C++, here is my code

int main () {
  ofstream myfile;
  myfile.open ("example.txt");
  myfile << "Writing this to a file.\n";
  myfile.close();
  return 0;
}

error from Dev-C++ 10

C:\devp\main.cpp aggregate `std::ofstream OutStream' has incomplete type and cannot be defined

Thanks in advance

解决方案

You can try this:

#include <fstream>
using namespace std;

int main () {
  ofstream myfile;
  myfile.open ("example.txt");
  myfile << "Writing this to a file.\n";
  myfile.close();
  return 0;
}

这篇关于ofstream错误在c ++的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆