Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Can I use the ANSI String Class in a normal class

Can I use the ANSI String Class in a normal class

Scheduled Pinned Locked Moved C / C++ / MFC
helpc++
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • T Offline
    T Offline
    Tom Moore
    wrote on last edited by
    #1

    Hi, I'm wondering if I can use the ANSI String Class in normal classes. I tried yesterday and got an error.

    Product.h

    #include
    #include
    using namespace std;
    class Product
    {
    public:
    Product(Product&);
    Product(string name, int amount , float price);
    float GetPrice();
    void SetPrice(float price);
    void SetAmount(int Amount);
    int GetAmount();
    void SetName(string name);
    string GetName();
    Product();
    virtual ~Product();
    private:
    float itsPrice;
    int itsAmount;
    string itsName;
    };

    Product.cpp

    Product::Product()
    {

    }

    Product::~Product()
    {

    }

    string Product::GetName()
    {
    return itsName;
    }

    void Product::SetName(string name)
    {
    itsName = name;
    }

    int Product::GetAmount()
    {
    return itsAmount;
    }

    void Product::SetAmount(int Amount)
    {
    itsAmount = Amount;
    }

    void Product::SetPrice(float price)
    {
    itsPrice = price;
    }

    float Product::GetPrice()
    {
    return itsPrice;
    }

    Product::Product(string name, int amount, float price)
    {
    itsName = name;
    itsAmount = amount;
    itsPrice = price;
    }

    Product::Product(Product &rhs)
    {
    itsName = rhs.GetName();
    itsPrice = rhs.GetPrice();
    itsAmount = rhs.GetAmount();
    }

    main.cpp

    #include "iostream.h"
    #include "Product.h"
    using namespace std;

    int main()
    {
    Product p1("Apple",0.25,50);

    cout << p1.GetName();
    int s;
    std::cin >> s;

    return 0;
    }

    The error is : error C2679: binary '<<' : no operator defined which takes a right-hand operand of type 'class std::basic_string,class std::allocator >' (or there is no acceptable conversion) Please help. Thanks in advance Tom -- modified at 8:04 Saturday 4th March, 2006

    G 1 Reply Last reply
    0
    • T Tom Moore

      Hi, I'm wondering if I can use the ANSI String Class in normal classes. I tried yesterday and got an error.

      Product.h

      #include
      #include
      using namespace std;
      class Product
      {
      public:
      Product(Product&);
      Product(string name, int amount , float price);
      float GetPrice();
      void SetPrice(float price);
      void SetAmount(int Amount);
      int GetAmount();
      void SetName(string name);
      string GetName();
      Product();
      virtual ~Product();
      private:
      float itsPrice;
      int itsAmount;
      string itsName;
      };

      Product.cpp

      Product::Product()
      {

      }

      Product::~Product()
      {

      }

      string Product::GetName()
      {
      return itsName;
      }

      void Product::SetName(string name)
      {
      itsName = name;
      }

      int Product::GetAmount()
      {
      return itsAmount;
      }

      void Product::SetAmount(int Amount)
      {
      itsAmount = Amount;
      }

      void Product::SetPrice(float price)
      {
      itsPrice = price;
      }

      float Product::GetPrice()
      {
      return itsPrice;
      }

      Product::Product(string name, int amount, float price)
      {
      itsName = name;
      itsAmount = amount;
      itsPrice = price;
      }

      Product::Product(Product &rhs)
      {
      itsName = rhs.GetName();
      itsPrice = rhs.GetPrice();
      itsAmount = rhs.GetAmount();
      }

      main.cpp

      #include "iostream.h"
      #include "Product.h"
      using namespace std;

      int main()
      {
      Product p1("Apple",0.25,50);

      cout << p1.GetName();
      int s;
      std::cin >> s;

      return 0;
      }

      The error is : error C2679: binary '<<' : no operator defined which takes a right-hand operand of type 'class std::basic_string,class std::allocator >' (or there is no acceptable conversion) Please help. Thanks in advance Tom -- modified at 8:04 Saturday 4th March, 2006

      G Offline
      G Offline
      Gary R Wheeler
      wrote on last edited by
      #2

      Hey Tom: Please repost your question, but this time place your code inside <pre></pre> tags, and click the "Ignore HTML tags in this message" checkbox. It's tough to read your code otherwise. Good luck.


      Software Zen: delete this;

      Fold With Us![^]

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups