-
C++ beginner
Okay i have this question: I am supposed to code the implementation of a person class (2 person objects are equal if they have the same name)
This is what i have done so far.
#include <iostream>
#include <string>
using namespace std;
class Person
{
public:
bool operator==(const Person&) const;
Person();
Person(string n);
private:
string name;
};
bool Person::operator ==(const Person& personName) const
{
return (name == personName.name);
}
Am i completely wrong ?? Or is it right any comments gr appre
-
sorted i think
I thought about it and made some changes.
#include <iostream>
#include <string>
using namespace std;
class Person
{
public:
string n;
public:
Person(string n)
{
this->n = n;
}
bool operator==(Person& obj);
Person();
};
bool Person::operator ==(Person& obj)
{
if(obj.n != this->n)
{
return false;
}
else
{
return true;
}
}
-
Scrap this previous question i got eventually. Does anyone know how i can read a text file with comma deliminated values.
-
Ultimate Member
For a file that has lines of the form "2,3.14,a" you can do something like:
fscanf (myFile, "%d,%f,%c\n", &myFloat,&myInt,&myChar);
More info on http://www.die.net/doc/linux/man/man3/fscanf.3.html
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
|