有关CEdit的成员函数GetLine()的用法,请教高手!50分赠送

citycity 2000-08-15 03:28:00
CEdit::GetLine(int nIndex,LPCTSTR lpszBuffer)const中LPCTSTR定义的是什么类型,怎样才能把读入到缓冲区“lpszBuffer"中的字符串读入到一个字符串变量中。多谢!
...全文
630 21 打赏 收藏 转发到动态 举报
写回复
用AI写文章
21 条回复
切换为时间正序
请发表友善的回复…
发表回复
ycc 2000-08-17
  • 打赏
  • 举报
回复
CString的用法应该是这样

CString str
wndEdit.GetLine(nIndex, str.GetBufferSetLength(100));
citycity 2000-08-16
  • 打赏
  • 举报
回复
还要请教softsprite:为什么nIndex的值在执行完GetLine后会变?
citycity 2000-08-15
  • 打赏
  • 举报
回复
to softsprite:不好意思,想给你加分,却加错了,以后多给你加点,多谢。
citycity 2000-08-15
  • 打赏
  • 举报
回复
to zhushiqi:你的方法还是不行,但还是谢谢你
citycity 2000-08-15
  • 打赏
  • 举报
回复
to softsprite:问题解决了,多谢多谢
zhushiqi 2000-08-15
  • 打赏
  • 举报
回复
i'm very sorry!
it should be
GetLine(index,(LPTSTR)&str);

i forget to add '&' char.
it should be right.
zhushiqi 2000-08-15
  • 打赏
  • 举报
回复
i'm very sorry .
it should be
GetLine(index,(LPTSTR)&str);

i just forget '&' char.
it should be right.
citycity 2000-08-15
  • 打赏
  • 举报
回复
to zhushiqi:也不对啊,又出现错误:error C2440: 'type cast' : cannot convert from 'class CString' to 'char *',怎么会是"char*",不是LPCTSTR吗,我快晕了,请再指教
citycity 2000-08-15
  • 打赏
  • 举报
回复
to bird2000:可现在问题是GetLine(int nIndex,LPCTSTR lpszBuffer)函数里的的“lpszBuffer"的类型怎么是”char*"?
citycity 2000-08-15
  • 打赏
  • 举报
回复
to zhushiqi:也不对啊,又出现错误:error C2440: 'type cast' : cannot convert from 'class CString' to 'char *',怎么会是"char*",不是LPCTSTR吗,我快晕了,请再指教
U皮特U 2000-08-15
  • 打赏
  • 举报
回复
CString的LPCTSTR操作符产生的字符串指针只能用于引用,不能用于直接向它赋值。因此zhushiqi的代码会产生错误。正确的做法可以象huntout说的那样,先读到一个缓冲区中,然后用CString strBuf = sBuf赋值。
citycity 2000-08-15
  • 打赏
  • 举报
回复
也不对啊,又出现错误:error C2440: 'type cast' : cannot convert from 'class CString' to 'char *',怎么会是"char*",不是LPCTSTR吗,我快晕了,请再指教
zhushiqi 2000-08-15
  • 打赏
  • 举报
回复
I'm sorry,
it should be
GetLine(index,(LPTSTR)str);

not LPCTSTR ,just LPTSTR
bird2000 2000-08-15
  • 打赏
  • 举报
回复
LPCTSTR: L - long
p - pointer
c - c language
t - type
str - string

在MFC中CString类中重载了LPCTSTR操作符,所以如softsprint说。
bird2000 2000-08-15
  • 打赏
  • 举报
回复
LPCTSTR:
citycity 2000-08-15
  • 打赏
  • 举报
回复
to zhushiqi:我用了你的方法,可是却出现错误:error C2664: 'int __thiscall CEdit::GetLine(int,char *) const' : cannot convert parameter 2 from 'const char *' to 'char *'Conversion loses qualifiers,这是为什么?
bird2000 2000-08-15
  • 打赏
  • 举报
回复
guanzhu
huntout 2000-08-15
  • 打赏
  • 举报
回复
//int GetLine( int nIndex, LPTSTR lpszBuffer ) const;
//int GetLine( int nIndex, LPTSTR lpszBuffer, int nMaxLength ) const;

//example:
char sBuf[101];
m_cEdit.GetLine(1, sBuf, 100);
U皮特U 2000-08-15
  • 打赏
  • 举报
回复
LPCTSTR是一个指向支持Unicode和DBCS的字符串的32位指针。

直接赋值给字符串变量即可:CString strBuf = lpszBuffer;
liang2001 2000-08-15
  • 打赏
  • 举报
回复
直接strcpy()
加载更多回复(1)

16,466

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC相关问题讨论
社区管理员
  • 基础类社区
  • Web++
  • encoderlee
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

        VC/MFC社区版块或许是CSDN最“古老”的版块了,记忆之中,与CSDN的年龄几乎差不多。随着时间的推移,MFC技术渐渐的偏离了开发主流,若干年之后的今天,当我们面对着微软的这个经典之笔,内心充满着敬意,那些曾经的记忆,可以说代表着二十年前曾经的辉煌……
        向经典致敬,或许是老一代程序员内心里面难以释怀的感受。互联网大行其道的今天,我们期待着MFC技术能够恢复其曾经的辉煌,或许这个期待会永远成为一种“梦想”,或许一切皆有可能……
        我们希望这个版块可以很好的适配Web时代,期待更好的互联网技术能够使得MFC技术框架得以重现活力,……

试试用AI创作助手写篇文章吧