MFC课设总结

1.CStringint

例如:

CString str=_T("10");

int num=0;

num=_tstoi(str);

num10.

2.intCString

例如:

CString s;

char ch[20];

int num=15;

itoa(num,ch,10);

s=ch;

s"15";

3.char []CString

例如:

CString s;

char ch[]="hello world";

s=ch;

s"hello world"

4.char *CString

例如:

CString str=_T("您好");

char *infor;

int strLength=str.GetLength()+1;

infor=new char[strLength];

strncpy(infor,str,strLength);

infor"您好",当然在这里用完之后记得delete[] infor,否则内存泄漏就不好了

这里得说一下MFC配置里面最好选择使用多字节字符集,不然上面有些转换可能不成功

 

PS:这个我郁闷了一下午才发现...

 

5.MFC下文件读取

例如:

CFile file(_T("帅哥计算器.txt"),CFile::modeRead);

char *pBuf;

DWORD dwFileLen;

dwFileLen=file.GetLength();

pBuf=new char[dwFileLen+1];

pBuf[dwFileLen]=0;

file.Read(pBuf,dwFileLen);

file.Close();

pBuf里面内容为帅哥计算器.txt文件内容,记得delete[] pBuf.

6.MFC下文件保存

例如:

CFile file(_T("我的文件.txt"),CFile::modeCreate | CFile::modeWrite);        

char infor[]="hello world";

file.Write(infor,strlen(infor));

file.Close();

这里保存模式可以自行选择,我用的是CFile::modeCreate | CFile::modeWrite.

 

最后想说一下有件奇怪的事,也感激一下PanBook.

就是我有个Place的类,加int x;成员,想写个void setX(int x);函数,但是在Place.cpp中用this->居然没有x出来...这个问题实在不好百度,结果咨询PanBook(相当给力),得知解决方法如下:

VS2010关了,然后删除ncb文件,重新打开VS,好了...如图

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值