C++“”字符与字符“”相加是连接

例如获取excel表头的函数,当列数超过26之后,列表头变为:AA,AB,AC.....,那么该如何获取呢?

eg:“A”+"A"="AA"

//自己写的获取单元头的函数  col:列数,row:行数  strName:表格名
void   GetCellName(int nRow, int nCol, CString &strName)
{
  int nSeed = nCol;//列数
CString strRow;


//比如nCol = 27 

int numberOfCol = nCol / 27;//numberOfCol =1
std::string  cellName;
if (numberOfCol!=0)
{
cellName = 'A' + numberOfCol-1;//cellName=A
nCol = nCol % 27+1;//nCol=1
}

cellName += 'A' + nCol - 1;//cellName = AA,为啥这样相加就可以组成AA ?因为 字符与字符相加是连接 
//cellName.append('A' + nCol - 1);//与上面一句完全等价   报错的原因是('A' + nCol - 1)是一个字符不是字符串
strName.Format(_T("%s"), cellName.c_str());
strRow.Format(_T("%d "), nRow);
strName = strName + strRow;

}

猜你喜欢

转载自blog.csdn.net/yimixgg/article/details/79798405