How to use a string in Object-Oriented Programming Cpp

How to use a string in Object-Oriented Programming Cpp

Are you new to object-oriented programming and wondering how to use a string in C++? Look no further. In this comprehensive guide, we will cover everything you need to know about using a string in object-oriented programming.

How to Use a String in Object-Oriented Programming C++

Introduction

Object-oriented programming is a popular programming paradigm that involves creating objects that contain data and functions. One of the most commonly used data types in object-oriented programming is the string. A string is a sequence of characters that can be used to represent text. In this guide, we will discuss how to use a string in object-oriented programming using C++.

How to Use a String in Object-Oriented Programming C++?

Example 1.

#include<iostream>
using namespace std;
class game
{
public:
    string name;
    string location;
    string character;
    void display()
    {
        cout<<name<<" "<<location<<"  "<<character<<endl;
    }
    game (string n,string l,string c)
    {
        name=n;
        location=l;
        character=c;
    }
};

int main()
{
    game play("rakib","dhaka","good");
    play.display();
    game play2("rana","mirpur","good");
    play2.display();
}

Object -Oriented Programming ful course

4 thoughts on “How to use a string in Object-Oriented Programming Cpp”

Leave a Comment