How use string ?

This is a discussion on How use string ? within the C++ Programming forums, part of the General Programming Boards category; 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); ...

  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 mystery Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    31,320
    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.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  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,672
    Code:
    #include"string.h"
    That should probably be:
    Code:
    #include <string>
    using std::string;
    I used to be an adventurer like you... then I took an arrow to the knee.

  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, 10:03 PM
  4. Classes inheretance problem...
    By NANO in forum C++ Programming
    Replies: 12
    Last Post: 12-09-2002, 02:23 PM
  5. Warnings, warnings, warnings?
    By spentdome in forum C Programming
    Replies: 25
    Last Post: 05-27-2002, 06:49 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21