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




