📄 productclassextraction.cpp
字号:
#include <iostream>
#include <string>
using namespace std;
class product
{
int number;
public:
string name;
int get_number(){return number;}
void set_number(int n){number = n;}
product(string text, int count);
friend ostream &operator<<(ostream &stream, product p);
friend istream &operator>>(istream &stream, product &p);
};
product::product(string text, int count)
{
name = text;
number = count;
}
istream &operator>>(istream &stream, product &p)
{
cin >> p.name >> p.number;
return stream;
}
ostream &operator<<(ostream &stream, product p)
{
cout << "Number of " << p.name << ": " << p.number << endl;
return stream;
}
main()
{
product oranges("", 0);
cout << "Please enter the product name and number: ";
cin >> oranges;
cout << oranges << endl;
return 0;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -