I am working on a Windows VC++2008 program that does fileIO, and have hit an issue that is really weird. in my #include directives I have
#include "stdafx.h"
#include <iostream>
#include <fstream>
#include <string>
and then I have a method that actually does the fileIO, but when I try to open the file like this:
std::ofstream Output;
Output.open("Output/log.txt", ios::out);
my intelisense allows it, and even has correct auto completes, but my compiler throws an error of:
1>c:...\engine\gsp420maincore\gsp420maincore\messagequeue.cpp(141) : error C2653: 'ios' : is not a class or namespace name
1>c:...\engine\gsp420maincore\gsp420maincore\messagequeue.cpp(141) : error C2065: 'out' : undeclared identifier
when I read about the ofstream.open() it stated that whether the file to be opened is for input, output, or both should be specified, but ios should be automatically included by any other iostream #include directive, and this problem is not corrected when I insert the:
#include <ios> // directive
the compiler has no complaints when I remove the second argument, but I know that I should try, and specify just in case I want to go in and read from a file as well as write to it. did I do something wrong?
It looks like you forgot to prefix it with
std::and you haven’t usedusing namespace std;(judging from the fact that you explicitly state the namespace forstd::ofstream).Try changing it to
std::ios::out.You should not need to
#include <ios>manually.