MFC平时代码记录

比较2个字符串是否相等

 

1、if(str1==str2)
2、if ( strcmp(str1,str2)==0 )
3、if (!str1.CompareNoCase( str2 ))

 

C++中引用(&)的用法,参数中遇到&的理解

 

  1. 引用就是某一变量(目标)的一个别名,对引用的操作与对变量直接操作完全一样。
  2. 引用的声明方法:数据类型 &引用名=目标变量名;
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);

 

 

 

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值