比较2个字符串是否相等
1、if(str1==str2)
2、if ( strcmp(str1,str2)==0 )
3、if (!str1.CompareNoCase( str2 ))
C++中引用(&)的用法,参数中遇到&的理解
- 引用就是某一变量(目标)的一个别名,对引用的操作与对变量直接操作完全一样。
- 引用的声明方法:数据类型 &引用名=目标变量名;
void main(void)
{
int i=3;
f(i);
cout << i;
}
void f(int& r)
{
r = 2*r;
}
这个函数运行结果是:6
但如果void f(int& r) 改为void f(int r) ,去掉引用&后,运行结果为:3
C++提供了一种更简明的通过引用的方式向函数传值,从函数中返回值。引用常作为函数的参数来使用,在函数的内部对引用进行操作,就相当于对原变量进行操作,这个用法类似于变量的指针。
CString转const char*
CString strPath = L"adfafs主声音文件fsfsa";
int nLength = strPath.GetLength();
int nBytes = WideCharToMultiByte(CP_ACP,0,strPath,nLength,NULL,0,NULL,NULL);
char* VoicePath = new char[ nBytes + 1];
memset(VoicePath,0,nLength + 1);
WideCharToMultiByte(CP_OEMCP, 0, strPath, nLength, VoicePath, nBytes, NULL, NULL);
VoicePath[nBytes] = 0;
const char*转CString
const char* cstr = "CSDN";
CString str(cstr);