-
數(shù)據(jù)類型。
查看全部 -
命名空間關(guān)鍵字? namespace
查看全部 -
初始化方法
查看全部 -
C與C++的關(guān)系
查看全部 -
return0是針對(duì)int main的,可以用void main()然后不加return來替換,但一般用前者,習(xí)慣性可以返回文件是否執(zhí)行成功的情況(int main就是標(biāo)準(zhǔn)返回值是整型,void main就是無返回值)。
而main()里面去的void是指main函數(shù)里沒有參數(shù),這是常見用法,也可以直接不加void同樣是沒有參數(shù),大多用這兩者,如果main()加參數(shù),則是int main(int argc, char * argv[]);
這個(gè)是帶參數(shù)的main函數(shù)的標(biāo)準(zhǔn)格式。
其中argc為命令行參數(shù)的個(gè)數(shù),包括可執(zhí)行文件名。
argv為一個(gè)字符串?dāng)?shù)組,共計(jì)有argc個(gè)元素,依次為命令行輸入的各個(gè)參數(shù)。其中argv[0]為執(zhí)行的文件名。
當(dāng)該main函數(shù)所在工程編譯出的可執(zhí)行文件被調(diào)用時(shí),參數(shù)會(huì)同時(shí)在命令行中傳遞。查看全部 -
#include <iostream>
#include <stdlib.h>
using namespace std;
? ? namespace? ? ?myNum? ? ? ? ? ? //填寫命名空間的關(guān)鍵字
{
? ? int x = 105;
}
int main()
{
? ? // 使用bool類型定義isOdd,作為狀態(tài)位
? ? ? ? bool? ? isFlag = false;? ? ? ?
if(myNum::x % 2 == 0)
{
//改變狀態(tài)位的值,使其為false
? ? ? ? isFlag = false;
}
else
{
? ? //改變狀態(tài)位的值,使其為true
? ? ? ? isFlag = true;
}
? ? // 判斷狀態(tài)位的值
if(isFlag)
{
// 如果狀態(tài)位的值為true,則打印變量x是奇數(shù)
? ? ? ? cout <<"變量x是奇數(shù)"<<endl;
}
else
{
? ? ? ? // 如果狀態(tài)位的值為false,則打印變量x是偶數(shù)
cout <<"變量x是偶數(shù)"<<endl;
}
return 0;
}
查看全部 -
#include<iostream>
#include<stdlib.h>
using namespace std;
int getMaxOrMin(int* arr, int count, bool isMax) {
?int temp = arr[0];
?for (int i = 0; i < count; i++) {
??if (isMax) {
???if (temp < arr[i])
????temp = arr[i];
??}
??else {
???if (temp > arr[i])
????temp = arr[i];
??}
?}
?return temp;
}
int main() {
?int arr[10];
?cout << "Please enter four digits" << endl;
?for (int i = 0; i < 4; i++) {
??cin >> arr[i];
?}
?bool flag;
?cout << "Do you want a maximum(1) or a minimum(0)?" << endl;
?cin >> flag;
?cout << "The required value is:" << getMaxOrMin(arr,4,flag) << endl;
}查看全部 -
命名空間的名字是不可以重復(fù)的
查看全部 -
在<<輸出前加上oct dec hex可以改變輸出數(shù)字的編碼,分別對(duì)應(yīng)八進(jìn)制,十進(jìn)制,十六進(jìn)制,如果想要輸出二進(jìn)制的數(shù)字需要引用bitset頭文件,然后講數(shù)字轉(zhuǎn)化為bitset再輸出,如 cout << bitset<32>(11)
輸出布爾值,需要加上boolalpha
如 cout << boolalpha << 1
查看全部 -
C++變量隨用隨定義~但是感覺現(xiàn)在基本沒有感受過不隨用隨定義的情況。
查看全部 -
C++提供復(fù)制初始化和直接初始化兩種初始化方法,二C只提供復(fù)制初始化
復(fù)制初始化例如 int x = 1024
直接初始化例如 int x (1024)
查看全部 -
c++中才出現(xiàn)布爾類型!
查看全部 -
c+初始化多一個(gè)int x(1024);查看全部
-
IDE集成開發(fā)環(huán)境查看全部
-
隨用隨定義,cout<輸出 cin>輸入 .cpp查看全部
舉報(bào)