CString :: GetAt的问题 [英] Problem with CString::GetAt

查看:213
本文介绍了CString :: GetAt的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





我有代码:



Hi,

I have the code:

CString buf;
buf.Preallocate(255);
GetWindowText(GetForegroundWindow(), buf.GetBuffer(), 255);

int Bracket = buf.Find("[");
char p = buf.GetAt(Bracket+1);





buf是:SONAR X1 Producer - [Two Track.cwp - Track]

Bracket是:20 - 所以它找到了''''字符。



我希望p为''T''



我所遇到的麻烦就是atlsimpstr.h中的一个断言line:



ATLASSERT((iChar> = 0)&&(iChar< = GetLength())); //索引''\ 0''是好的



iChar是21并且小于字符串长度。



什么可能是我的问题?



buf is: "SONAR X1 Producer - [Two Track.cwp - Track]"
Bracket is: 20 - So it found the ''['' character.

I want p to be ''T''

All I get for my trouble is an assertion in atlsimpstr.h at line:

ATLASSERT( (iChar >= 0) && (iChar <= GetLength()) ); // Indexing the ''\0'' is OK

iChar is 21 and less than the string length.

What the diddly hoo could be my problem?

推荐答案

你需要做的就是致电:



All you need to do is to call:

buf.ReleaseBuffer();





后你的



after your

GetWindowText(GetForegroundWindow(), buf.GetBuffer(), 255);





更好,将GetWindowText行修改为:





Better of, modify the GetWindowText line to:

GetWindowText(GetForegroundWindow(), CStrBuf(buf, 255), 255);



并摆脱Preallocate()。在这种情况下,您不再需要担心ReleaseBuffer()。阅读 CStrBuf [ ^ ]在MSDN中获取更多信息。这是一个非常方便的包装


and get rid of Preallocate(). In this case you would not need to worry about ReleaseBuffer() anymore. Read about CStrBuf[^] in MSDN for more information. It''s a very handy wrapper


这篇关于CString :: GetAt的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆