#include<iostream>
#include<string>
using namespace std;
class Car
{
private:
string brand;
string model;
string color;
public:
void car( string brand, string model, string color)
//void car()括号里要有形参,不然下面的值传不过来。
{
this->brand = brand;
this->model = model;
this->color = color;
}
void displayInfo() {
cout << "Car Information:" << endl;
cout << "Brand: " << brand << endl;//在类里输出直接cuot<<brand,不用car.brand.
cout << "Model: " << model << endl;
cout << "Color: " << color << endl;
}
};
int main()
{
Car c;
c.car("奥迪","A8","黑色");
c.displayInfo();//c.displayInfo就能直接输出了,不用cuot<<displayInfo;
return 0;
}
#include<iostream>
#include<string>
using namespace std;
class Car
{
private:
string brand;
string model;
string color;
public:
void car( string brand, string model, string color)
//void car()括号里要有形参,不然下面的值传不过来。
{
this->brand = brand;
this->model = model;
this->color = color;
}
void displayInfo() {
cout << "Car Information:" << endl;
cout << "Brand: " << brand << endl;//在类里输出直接cuot<<brand,不用car.brand.
cout << "Model: " << model << endl;
cout << "Color: " << color << endl;
}
};
int main()
{
Car c;
c.car("奥迪","A8","黑色");
c.displayInfo();//c.displayInfo就能直接输出了,不用cuot<<displayInfo;
return 0;
}
标签:string,color,brand,c++,void,model,汽车信息,cout
From: https://blog.csdn.net/2301_80772563/article/details/137146829