Author |
Message |
deltatux
![](http://compsci.ca/v3/uploads/user_avatars/2510662304931ac0b5cb22.png)
|
Posted: 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 |
|
|
|
|
![](images/spacer.gif) |
Sponsor Sponsor
![Sponsor Sponsor](templates/subSilver/images/ranks/stars_rank5.gif)
|
|
![](images/spacer.gif) |
DemonWasp
|
Posted: 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. |
|
|
|
|
![](images/spacer.gif) |
md
![](http://compsci.ca/v3/uploads/user_avatars/1849317514ed6c4399768d.png)
|
Posted: 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. |
|
|
|
|
![](images/spacer.gif) |
deltatux
![](http://compsci.ca/v3/uploads/user_avatars/2510662304931ac0b5cb22.png)
|
Posted: 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 |
|
|
|
|
![](images/spacer.gif) |
DemonWasp
|
Posted: 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 . |
|
|
|
|
![](images/spacer.gif) |
deltatux
![](http://compsci.ca/v3/uploads/user_avatars/2510662304931ac0b5cb22.png)
|
Posted: Tue Feb 03, 2009 4:04 pm Post subject: RE:VS2008: Error C2679 help? |
|
|
How do I do that?
deltatux |
|
|
|
|
![](images/spacer.gif) |
wtd
|
Posted: 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. |
|
|
|
|
![](images/spacer.gif) |
wtd
|
Posted: 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? |
|
|
|
|
![](images/spacer.gif) |
Sponsor Sponsor
![Sponsor Sponsor](templates/subSilver/images/ranks/stars_rank5.gif)
|
|
![](images/spacer.gif) |
deltatux
![](http://compsci.ca/v3/uploads/user_avatars/2510662304931ac0b5cb22.png)
|
Posted: 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 |
|
|
|
|
![](images/spacer.gif) |
|