读书人

字符串怎么转换?

发布时间: 2012-03-19 22:03:04 作者: rapoo

字符串如何转换???
如何处理str_dealPathStr函数???
下面的程序调用word的VBA.程序中文件名filename为: "C:\Documents and Settings\yuntian\桌面\test\test.JPG " 如何通过str_dealPathStr函数处理
将字符变为: "C:\\Documents and Settings\\yuntian\\桌面\\test\\test.JPG "?


//插入图片
string put_Picture(const char *filename)
{
string str;
str= "Word.Selection.InlineShapes.AddPicture(\ " "
str+=str_dealPathStr(filename);
str+= "\ ")\n ";
//C:\\Documents and Settings\\yuntian\\桌面\\test\\test.JPG\ ") ";
str+= "\nWord.Selection.ParagraphFormat.Alignment = wdAlignParagraphCenter ";
str+= "\n ";

return str;
}

[解决办法]
string str_dealPathStr(const char* path)
{
string str;
const char* p = path;
char ch;
while (ch = *p++)
{
if (ch == '\\ ')
str += "\\ ";
else
str += ch;
}
return str;
}
[解决办法]
string str_dealPathStr(const char* path)
{
string str;
const char* p = path;
char ch;
while (ch = *p++)
{
if (ch == '\\ ')
str += "\\\\ ";
else
str += ch;
}
return str;
}

读书人网 >C++

热点推荐