i have a C++ Compiling error and cant figure out what it is can you help me?

ok I'm using the Irrlicht engine and im using Dev-C++ these are my #includes:

#include <irrlicht.h>

#include <IEventReceiver.h>

#include "Keycodes.h"

#include <stdio.h>

#include "CMainMenu.h"

#include <cstdlib>

#include <iostream>

#include <istream>

#include <ostream>

#include <fstream>

#include <iomanip>

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->getPosition();

ofstream myFile("test.txt");

myFile << v;

myFile.close();

}

now when i try to compile this program it gives me this error

no match for 'operator<<' in 'myFile << v'

and i cant figure out what is wrong with this i have all the includes and namespaces PLEASE HELP

thanks in advanced

Update:

1 i dont need the file...if the program cant find one then it wil create it

2 you are correct there i just added those in to see if it would affect anything and i never took it out

Update 2:

i found out the problem for some odd reason i cannot write this to a file:

core::vector3df v = camera->getPosition();

2 Answers

Relevance
  • Anonymous
    1 decade ago
    Favorite Answer

    Just check the following code written by you...

    Line1: int edit(int a, int b)

    Line2: {

    Line3: core::vector3df v = camera->getPosition();

    Line4: ofstream myFile("test.txt");

    Line5: myFile << 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 "<<" and ">>" overloaded operators are defined only for the built in types and not for the userdefined class objects..

    But you are trying to use "<<" 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 "<<" operator in your class definition.

    Only then it will work...

    Other part of the code is okay..

    .

    • Login to reply the answers
  • 1 decade ago

    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.

    • Login to reply the answers
Still have questions? Get your answers by asking now.