C++vetor问题????

闪耀 发布于 2013/09/29 17:33
阅读 268
收藏 0
#include "stdafx.h"
 

#define BNR 2

#define OCT 8

#define HEX 16

 

void ConvToBinary(int iDecim)

{

    int iRem = 0;

    vector<int> vecBnr;

    while(iDecim > BNR)

    {

        iRem = iDecim % BNR;

        vecBnr.push_back(iRem);

 

        iDecim = iDecim / BNR;

    }

    vecBnr.push_back(iDecim);
 

    cout<<"  ";

    int iSize = vecBnr.size() - 1; 

    for(int i = iSize; i >= 0; i--)

   {

        cout<<vecBnr[i];

    }
    cout<<"\n";

}

 

void ConvToOctal(int iDecim)

{
    int iRem = 0;

    vector<int> vecOct;

    while(iDecim > OCT)

    {

        iRem = iDecim % OCT;

        vecOct.push_back(iRem);

 
        iDecim = iDecim / OCT;

    }

   vecOct.push_back(iDecim);

 

    cout<<"  ";

    int iSize = vecOct.size() - 1;

    for(int i = iSize; i >= 0; i--)

    {
        cout<<vecOct[i];

    }

    cout<<"\n";

}

 

void ConvToHex(int iDecim)

{

    int iRem = 0;
    vector<int> vecHex;

    while(iDecim > HEX)

    {
        iRem = iDecim % HEX;

        vecHex.push_back(iRem);

 

        iDecim = iDecim / HEX;

    }

    vecHex.push_back(iDecim);

 

    cout<<"  ";

    int iSize = vecHex.size() - 1;

    for(int i = iSize; i >= 0; i--)

    {

        if(vecHex[i] > 9)

        {

            char ch;

            ch = vecHex[i] + 55;

            cout<<ch;

        }

        else

        {

            cout<<vecHex[i];

        }

    }

    cout<<"\n";

}

 

int _tmain(int argc, _TCHAR* argv[])

{

    int iDecim;

    int iNum;

    cout<<">>Please Input A Decimal:"<<"\n  ";

    cin>>iDecim;

    cout<<">>Convert Menu:"<<endl;

    cout<<"  1.Convert To Binary"<<endl;

    cout<<"  2.Convert To Octal"<<endl;

    cout<<"  3.Convert To Hex"<<endl;

    cout<<"  0.Exit"<<endl;

    cout<<">>Choose Change Num: ";

    cin>>iNum;

 

    switch(iNum)

    {

    case 1:

        ConvToBinary(iDecim);

        break;

 

    case 2:

        ConvToOctal(iDecim);

        break;

 

    case 3:

        ConvToHex(iDecim);

        break;

 

    case 0:

        break;

 

    default:

        break;

    }

 

    return 0;


}

这代码中标有红色背景的那几句代码是什么意思啊?有什么作用?求解释,不懂....

加载中
0
lcl
lcl
int 类型的动态数组, C++ 的标准库
0
stupidgrass
stupidgrass
www.google.com 程序猿们要学会借用搜索引擎哈
0
铂金小虎
铂金小虎
<c++ primer>有好几章都在讲这个类型
0
梅开源
梅开源
<c++ primer> 向量一节网上免费阅读
0
macwe
macwe

相当于 int vecBnr[99999999999999999999999999];

他是一个对象,表示一个动态管理长度的数组。

这里的知识点是:模板

返回顶部
顶部