简体   繁体   English

使用xcode处理C ++。 简单的流出来不起作用

[英]File Handling C++ with xcode. simple ofstream out not working

I wanted to do simple file handling test program in Xcode. 我想用Xcode做一个简单的文件处理测试程序。 But it gives me an error. 但这给了我一个错误。

#include <iostream>
#include <fstream.h>
using namespace std;

int main() {
    ofstream out("test");
    out<<"pen"<<"\t";
    out<<"25";
}

Error: 错误:

Implicit instantiation of undefined template std::basic_ofstream<char> 未定义模板std::basic_ofstream<char>隐式实例化

The first error means that you have to write fstream instead of fstream.h . 第一个错误意味着您必须编写fstream而不是fstream.h。 The second error would be caused by the first one. 第二个错误将由第一个错误引起。 Look at my g++'s output when I try to compile your example: 当我尝试编译您的示例时,请查看我的g ++输出:

example.cpp:2:21: fatal error: fstream.h: No such file or directory compilation terminated. example.cpp:2:21:致命错误:fstream.h:没有此类文件或目录编译终止。

In this link, you will find ofstream's class specification. 在此链接中,您将找到ofstream的类规范。 I think it can be helpful for you: 我认为这可能对您有帮助:

http://www.cplusplus.com/reference/fstream/ofstream/ http://www.cplusplus.com/reference/fstream/ofstream/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM