在mfc下,调用CString时候要加入头文件: afx.h; afxstr.h;
在atl下,调用CString时候要加入: atlstr.h;
下面是个简单的例子:
///.cpp
#include "stdafx.h"
.......
CString a;
CString s[2];
int y[2] = { 10, 11 };
int i;
for( i = 1; i >= 0 ; i-- )
{
if( y[i] == 10 )
{
y[i] = 0xa;
s[i].Format( "%x", y[i] );
}
else if( y[i] == 11 )
{
y[i] = 0xb;
s[i].Format( "%x", y[i] );
}
}
for( i = 0; i < 2; i++ )
{
a += s[i];
}
printf( "%s", a );
..........
/.h
#include <iostream>
#include <tchar.h>
//#include <windows.h>
#include <atlstr.h>