dcsimg
Results 1 to 4 of 4

Thread: C++ beginner

  1. #1
    Junior Member
    Join Date
    Oct 2006
    Posts
    10

    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

  2. #2
    Junior Member
    Join Date
    Oct 2006
    Posts
    10

    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;
    }
    }

  3. #3
    Junior Member
    Join Date
    Oct 2006
    Posts
    10
    Scrap this previous question i got eventually. Does anyone know how i can read a text file with comma deliminated values.

  4. #4
    Ultimate Member bassman's Avatar
    Join Date
    Feb 2002
    Location
    Portugal
    Posts
    2,384
    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
  •