課程
/后端開發(fā)
/C++
/C++遠征之封裝篇(上)
為什么我在VS上運行,它直接跳出去了啊,但顯示的是運行成功
2017-12-27
源自:C++遠征之封裝篇(上) 3-2
正在回答
你在vs上 用 開始執(zhí)行(不調(diào)試) 這樣就不會跳出去了?? 快捷鍵是F5
在開頭加上#include<stdlib.h>;然后return0;前面加上system("pause");代碼,是使運行時屏幕不立馬消失 可以顯示出來的功能,像老師之前的代碼都有寫這條語句
以下是我的代碼
#include <iostream>#include <string>using namespace std;
/*** 定義類:Student* 數(shù)據(jù)成員:名字、年齡*/class Student{public:?string m_strName;?int m_iAge;
?// 定義數(shù)據(jù)成員名字 m_strName 和年齡 m_iAge};
int main(){?Student stu;// 實例化一個Student對象stu
????// 設(shè)置對象的數(shù)據(jù)成員?stu.m_strName = "慕課網(wǎng)";?stu.m_iAge = 2;
?// 通過cout打印stu對象的數(shù)據(jù)成員?cout << stu.m_strName << " " << stu.m_iAge << endl;?return 0;}
舉報
封裝--面向?qū)ο蟮幕?,本教程力求幫助小伙伴們即學(xué)即會
Copyright ? 2025 imooc.com All Rights Reserved | 京ICP備12003892號-11 京公網(wǎng)安備11010802030151號
購課補貼聯(lián)系客服咨詢優(yōu)惠詳情
慕課網(wǎng)APP您的移動學(xué)習(xí)伙伴
掃描二維碼關(guān)注慕課網(wǎng)微信公眾號
2018-06-17
你在vs上 用 開始執(zhí)行(不調(diào)試) 這樣就不會跳出去了?? 快捷鍵是F5
2018-03-09
在開頭加上#include<stdlib.h>;然后return0;前面加上system("pause");代碼,是使運行時屏幕不立馬消失 可以顯示出來的功能,像老師之前的代碼都有寫這條語句
2017-12-27
以下是我的代碼
#include <iostream>
#include <string>
using namespace std;
/**
* 定義類:Student
* 數(shù)據(jù)成員:名字、年齡
*/
class Student
{
public:
?string m_strName;
?int m_iAge;
?// 定義數(shù)據(jù)成員名字 m_strName 和年齡 m_iAge
};
int main()
{
?Student stu;// 實例化一個Student對象stu
????// 設(shè)置對象的數(shù)據(jù)成員
?stu.m_strName = "慕課網(wǎng)";
?stu.m_iAge = 2;
?// 通過cout打印stu對象的數(shù)據(jù)成員
?cout << stu.m_strName << " " << stu.m_iAge << endl;
?return 0;
}