在 Windows C++ 中使用 fileIO
我正在尝试在我的windows VC++2008(这是我为我需要做的一切设置的)程序中使用fileIO,并且我已经完成了以下
#include <iostream>
#include <fstream>
#include <string>
....
ostream Output;
intelisense工作正常,甚至为我提供了对象的方法,但我的编译器抛出它无法识别 ostream,即使我知道它驻留在包含的 fstream 头文件中。
我的编译器有问题吗?我该如何检查?
附加信息
我已经完成了以下操作,它现在可以识别流,但是
std::ofstream Output // instead of ostream Output
Output.open("Output/log.txt", ios::out); //so that I can open the file and specify output as ofstream can go both ways.
当我尝试将其作为一行仅使用构造函数执行此操作时,
1>c:...\engine\gsp420maincore\gsp420maincore\messagequeue.cpp(141) : error C2664: 'std::basic_ostream<_Elem,_Traits>::basic_ostream(std::basic_streambuf<_Elem,_Traits> *,bool)' : cannot convert parameter 1 from 'const char [15]' to 'std::basic_streambuf<_Elem,_Traits> *'
1> with
1> [
1> _Elem=char,
1> _Traits=std::char_traits<char>
1> ]
1> Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
我现在遇到了一个不同的错误,当我使用当前方法时,我的编译器指出,我遇到了这个问题
error C2653: 'ios' : is not a class or namespace name
I am trying to use fileIO in my windows VC++2008 (this is what I have set up for everything I need to do) program, and I have done the following
#include <iostream>
#include <fstream>
#include <string>
....
ostream Output;
intelisense is working fine, and even gives me the methods for the object, but my compiler throws that it does not recognize ostream even though I know that it resides in the fstream header file that is included.
is there something wrong with my compiler, and how do I check?
additional info
I have done the following, and it now recognizes the stream, but I now get a different error
std::ofstream Output // instead of ostream Output
Output.open("Output/log.txt", ios::out); //so that I can open the file and specify output as ofstream can go both ways.
when I tried to do this as one line with just a constructor I got this issue"
1>c:...\engine\gsp420maincore\gsp420maincore\messagequeue.cpp(141) : error C2664: 'std::basic_ostream<_Elem,_Traits>::basic_ostream(std::basic_streambuf<_Elem,_Traits> *,bool)' : cannot convert parameter 1 from 'const char [15]' to 'std::basic_streambuf<_Elem,_Traits> *'
1> with
1> [
1> _Elem=char,
1> _Traits=std::char_traits<char>
1> ]
1> Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
when I use the current method my compiler states that
error C2653: 'ios' : is not a class or namespace name
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果您尝试输出到文件,则可以使用
ofstream
:如果您不
使用
std,则需要std::
命名空间。You could use
ofstream
if you're trying to output to a file:The
std::
is needed if you're notusing
the std namespace.您尝试过 std::ostream 吗?您可能没有包含名称空间?
Have you tried std::ostream? You might not have included the namespace?