ok I'm using the Irrlicht engine and im using Dev-C++ these are my #includes:
#include %26lt;irrlicht.h%26gt;
#include %26lt;IEventReceiver.h%26gt;
#include "Keycodes.h"
#include %26lt;stdio.h%26gt;
#include "CMainMenu.h"
#include %26lt;cstdlib%26gt;
#include %26lt;iostream%26gt;
#include %26lt;istream%26gt;
#include %26lt;ostream%26gt;
#include %26lt;fstream%26gt;
#include %26lt;iomanip%26gt;
and theese namespaces:
using namespace std;
using namespace irr;
using namespace core;
using namespace scene;
using namespace video;
using namespace io;
using namespace gui;
using namespace std;
now in my program i have ths function:
int edit(int a, int b)
{
core::vector3df v = camera-%26gt;getPosition();
ofstream myFile("test.txt");
myFile %26lt;%26lt; v;
myFile.close();
}
now when i try to compile this program it gives me this error
no match for 'operator%26lt;%26lt;' in 'myFile %26lt;%26lt; v'
and i cant figure out what is wrong with this i have all the includes and namespaces PLEASE HELP
thanks in advanced
I have a C++ Compiling error and cant figure out what it is can you help me?
Just check the following code written by you...
Line1: int edit(int a, int b)
Line2: {
Line3: core::vector3df v = camera-%26gt;getPosition();
Line4: ofstream myFile("test.txt");
Line5: myFile %26lt;%26lt; v;
Line6: myFile.close();
Line7: }
In line 3 you are declaring a variable "v" of type "core::vector3df".
In line5 you are trying to write the contents of "v" to myFile.
Here you are getting error.
This is because of the fact, that "%26lt;%26lt;" and "%26gt;%26gt;" overloaded operators are defined only for the built in types and not for the userdefined class objects..
But you are trying to use "%26lt;%26lt;" operator for an object of user defined class...In case you want to do this, first of all, you have to write code to overload the "%26lt;%26lt;" operator in your class definition.
Only then it will work...
Other part of the code is okay..
.
Reply:I'm not an expert on C++ so some of the questions I might be asking you might just be a total waste of your time so I apologize in advance.
According to the error statement, you might want to check if you have a file named test.txt in the same directory and what is in it.
The fourth line in your program starts with "ofstream". You have #include's for "fstream" and "ostream" and I'm thinking this may just be a typo.
cheap flowers
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment