Thread: How use string ?

  1. #1
    Registered User
    Join Date
    Oct 2006
    Posts
    3

    How use string ?

    code:
    //File:Str.h

    #ifndef STR_H
    #define STR_H
    #include"string.h"
    class Str
    {
    public:
    Str();
    void setId(int);
    void setName(string);
    void setPrice(int);
    void setStock(int);
    void Display()const;
    int getId()const;
    string getName()const;
    int getPrice()const;
    int getStock()const;

    private:
    int id;
    string name;
    int price;
    int stock;
    };
    #endif
    /--------------------------------------------------------------------/
    //File:Str.cpp

    #include"Str.h"
    #include<iostream>
    #include<string>

    using namespace std;

    Str::Str()
    {
    id = 0;
    name = "empty";
    price = 0;
    stock = 0;
    }

    void Str::setId(int val)
    {
    id = val;
    }

    void Str::setName(string val)
    {
    name = val;
    }

    void Str::setPrice(int val)
    {
    price = val;
    }

    void Str::setStock(int val)
    {
    stock = val;
    }

    void Str:isplay()const
    {
    cout<<"ID = "<<id<<endl;
    cout<<"Name = "<<name<<endl;
    cout<<"Price = "<<price<<endl;
    cout<<"Stock = "<<stock<<endl;
    }

    int Str::getId()const
    {
    return id;
    }

    string Str::getName()const
    {
    return name;
    }

    int Str::getPrice()const
    {
    return price;
    }

    int Str::getStock()const
    {
    return stock;
    }
    /--------------------------------------------------------------------/

    Please help me.How to use string in this code?

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    How to read "please read before posting code"
    How to read "use code tags"
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #3
    Registered User
    Join Date
    Oct 2006
    Posts
    3

    sorry

    I'm sorry.
    Code:
    //File:Str.h
    
    #ifndef STR_H
    #define STR_H
    #include"string.h"
    class Str
    {
    public:
    	Str();
    	void setId(int);
    	void setName(string);
    	void setPrice(int);
    	void setStock(int);
    	void Display()const;
    	int getId()const;
    	string getName()const;
    	int getPrice()const;
    	int getStock()const;
    
    private:
    	int id;
    	string name;
    	int price;
    	int stock;
    };
    #endif
    
    //File:Str.cpp
    
    #include"Str.h"
    #include<iostream>
    #include<string>
    
    using namespace std;
    
    Str::Str()
    {
    	id = 0;
    	name = "empty";
    	price = 0;
    	stock = 0;
    }
    
    void Str::setId(int val)
    {
    	id = val;
    }
    
    void Str::setName(string val)
    {
    	name = val;
    }
    
    void Str::setPrice(int val)
    {
    	price = val;
    }
    
    void Str::setStock(int val)
    {
    	stock = val;
    }
    
    void Str::Display()const
    {
    	cout<<"ID = "<<id<<endl;
    	cout<<"Name = "<<name<<endl;
    	cout<<"Price = "<<price<<endl;
    	cout<<"Stock = "<<stock<<endl;
    }
    
    int Str::getId()const
    {
    	return id;
    }
    
    string Str::getName()const
    {
    	return name;
    }
    
    int Str::getPrice()const
    {
    	return price;
    }
    
    int Str::getStock()const
    {
    	return stock;
    }
    Help me please.how to use string?

  4. #4
    Registered User hk_mp5kpdw's Avatar
    Join Date
    Jan 2002
    Location
    Northern Virginia/Washington DC Metropolitan Area
    Posts
    3,817
    Code:
    #include"string.h"
    That should probably be:
    Code:
    #include <string>
    using std::string;
    "Owners of dogs will have noticed that, if you provide them with food and water and shelter and affection, they will think you are god. Whereas owners of cats are compelled to realize that, if you provide them with food and water and shelter and affection, they draw the conclusion that they are gods."
    -Christopher Hitchens

  5. #5
    Registered User
    Join Date
    Oct 2006
    Posts
    3
    thank you very much.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. compare structures
    By lazyme in forum C++ Programming
    Replies: 15
    Last Post: 05-28-2009, 02:40 AM
  2. OOP Question DB Access Wrapper Classes
    By digioz in forum C# Programming
    Replies: 2
    Last Post: 09-07-2008, 04:30 PM
  3. Message class ** Need help befor 12am tonight**
    By TransformedBG in forum C++ Programming
    Replies: 1
    Last Post: 11-29-2006, 11:03 PM
  4. Classes inheretance problem...
    By NANO in forum C++ Programming
    Replies: 12
    Last Post: 12-09-2002, 03:23 PM
  5. Warnings, warnings, warnings?
    By spentdome in forum C Programming
    Replies: 25
    Last Post: 05-27-2002, 06:49 PM