如何将char数组复制到CString? [英] How to copy char array to CString?
本文介绍了如何将char数组复制到CString?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个带有一些文本的文件.我想做2个任务
1.打开文件时,在文件末尾添加mac_address.
2.用字母"P"替换字符串中的第一个字符
I have a file with some text. I want to do 2 tasks
1.append the file with mac_address at end of the text when i open it.
2.Replace first char in the string with Letter ''P''
while (readFile.ReadString(strLine))
{
CString s=strLine;
.....
if(s[0]=='L')
{
for(int temp=0;temp<18;temp++)
{
s[m]=mac_address[temp];//here is the error
}
s[0]=_T('P');// here is the error
}
推荐答案
CString
构造函数应完成此任务,即:
CString
constructor should do the job, namely:
CString s(mac_address);
请注意,如果您正在执行UNICODE
构建,则构造函数会执行将提供的char
转换为wide char
的必要转换.
[更新]
Beware if you are doing a UNICODE
build then the constructor performs the necessary conversion of the provided char
s into wide char
ones.
[update]
if ( s.Left(1)==_T("L") )
{
s = _T("P");
for(int i = 1; i < 18; i++)
{
s += mac_address[i];
}
}
[/update]
使用
Use CString::SetAt(), to change the value at any index.
s[m]=mac_address[temp];
//can be written as
if(m>=0 && m<s.getlength())>
{
s[m]=mac_address[temp];
}
s+=mac_address;
追加到文本的末尾.
appends to the end of the text.
这篇关于如何将char数组复制到CString?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文