主页
C++
C++ 类和对象
demo_object_attr
运行 ❯
×
更改方向
保存代码
更改主题
#include
#include
using namespace std; class MyClass { // The class public: // Access specifier int myNum; // Attribute (int variable) string myString; // Attribute (string variable) }; int main() { MyClass myObj; // Create an object of MyClass // Access attributes and set values myObj.myNum = 15; myObj.myString = "Some text"; // Print values cout << myObj.myNum << "\n"; cout << myObj.myString; return 0; }
15
Some text