Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 VS2008: Error C2679 help?
Index -> Programming, C++ -> C++ Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
deltatux




PostPosted: Tue Feb 03, 2009 12:50 am   Post subject: VS2008: Error C2679 help?

Hey guys,

I'm trying to open a file, however, I'm running into problems:

TDirectory.cpp
code:

#include <iostream>
using namespace std;
#include <fstream>
#include "TDirectory.h"
bool Listing::loadFileData(FILE* fp){
        fseek(fp, 0, SEEK_SET);
        ifstream in(fp);
        while (in) {
                in >> givenName >> surname >> address >> telephone;
        }
}


TDirectory.h
code:

struct Listing {
        char fname[16], lname[16], addr[16], phnum[16];

public:
        bool loadFileData(FILE *fp);
    const char* givenName() const;
    const char* surname() const;
    const char* address() const;
    const char* telephone() const;
};

struct Directory {
        FILE *fp;
        int records;
        struct Listing *listings;

public:
        bool loadFileData(const char* filename);
        void display() const;
        void close();
};


Error:
Quote:

error C2679: binary '>>' : no operator found which takes a right-hand operand of type 'overloaded-function' (or there is no acceptable conversion)


If I can't get this fixed, I might be forced to mix C with C++ and it'll go ugly...

Many thanks,
deltatux
Sponsor
Sponsor
Sponsor
sponsor
DemonWasp




PostPosted: Tue Feb 03, 2009 9:17 am   Post subject: RE:VS2008: Error C2679 help?

Your input statement:
code:
in >> givenName >> surname >> address >> telephone;


is trying to read strings into your getter functions. That's probably not what you meant.
md




PostPosted: Tue Feb 03, 2009 12:07 pm   Post subject: RE:VS2008: Error C2679 help?

Furthermore, character strings are a C construct. When using C++ you should use std::string wherever possible.
deltatux




PostPosted: Tue Feb 03, 2009 1:48 pm   Post subject: RE:VS2008: Error C2679 help?

So should I just read them directly into chars in the struct?

it worked on my other software but am having a tough time with this one =s...

deltatux
DemonWasp




PostPosted: Tue Feb 03, 2009 1:50 pm   Post subject: RE:VS2008: Error C2679 help?

No, just use the >> operator and change the types of your string variables to be std::string .
deltatux




PostPosted: Tue Feb 03, 2009 4:04 pm   Post subject: RE:VS2008: Error C2679 help?

How do I do that?

deltatux
wtd




PostPosted: Tue Feb 03, 2009 4:55 pm   Post subject: RE:VS2008: Error C2679 help?

While you're at it, mixing C file handling and C++ iostreams is a good way to give yourself a headache.
wtd




PostPosted: Tue Feb 03, 2009 5:11 pm   Post subject: RE:VS2008: Error C2679 help?

Think about what the error is telling you:

code:
error C2679: binary '>>' : no operator found which takes a right-hand operand of type 'overloaded-function' (or there is no acceptable conversion)


For the binary operator >> it's getting a right-hand operator of type overloaded-function.

What does this mean?
Sponsor
Sponsor
Sponsor
sponsor
deltatux




PostPosted: Tue Feb 03, 2009 5:27 pm   Post subject: Re: RE:VS2008: Error C2679 help?

wtd @ Tue Feb 03, 2009 4:55 pm wrote:
While you're at it, mixing C file handling and C++ iostreams is a good way to give yourself a headache.


Unfortunately, at my college, they came up with this brilliant idea by mixing C with C++ since we did C last semester, so they thought that by mixing C in C++ it'll make the transition easier =S... I think they shouldn't have done that.

It's very confusing.

and I don't understand the error at all >.<"

deltatux
Display posts from previous:   
   Index -> Programming, C++ -> C++ Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 9 Posts ]
Jump to:   


Style:  
Search: