【2016-12-3】C++控制台第一个程序示例

    xiaoxiao2021-12-14  19

    复习面向对象技术课程,顺便学习一下C++基本语法、格式

    C++入门-->第一个C++控制台程序

    主程序Source.cpp:(没有写Source.h)

    #include "iostream" #include "Stu.h" using namespace std; int add(int a, int b) { return a + b; } int main() { int a, b; cin >> a >> b; cout << a << endl << b << endl; int c; c = add(a, b); cout << c << endl; Stu *stu=new Stu(10,"Kobe Bryant"); (*stu).printid(); Stu stu1(24,"小飞侠"); stu1.printid(); return 0; }类Stu:

    Stu.h:

    #pragma once #include <iostream> #include <string> using namespace std; class Stu { public: int id; string name; public: Stu(int id,string name); ~Stu(); public: void printid(); };Stu.cpp

    #include "Stu.h" Stu::Stu(int id,string name) { this->id = id; this->name = name; } Stu::~Stu() { } void Stu::printid() { cout <<id << endl; cout << name << endl; }

    转载请注明原文地址: https://ju.6miu.com/read-969146.html

    最新回复(0)