首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C++ >

strlen使用出错,该怎么处理

2012-03-06 
strlen使用出错intlenlenstrlen(m_strPath1)while(m_strPath1[len]! \ )--lenstrcat(m_strPath1,

strlen使用出错
int   len;
len=strlen(m_strPath1);
while(m_strPath1[len]!= "\ ")
--len;
strcat(m_strPath1, "result.txt ");

cpp(271)   :   error   C2001:   newline   in   constant
FmodelDlg.cpp(272)   :   error   C2105:   '-- '   needs   l-value
FmodelDlg.cpp(272)   :   error   C2446:   '!= '   :   no   conversion   from   'char   * '   to   'int '
                This   conversion   requires   a   reinterpret_cast,   a   C-style   cast   or   function-style   cast
FmodelDlg.cpp(272)   :   error   C2040:   '!= '   :   'int '   differs   in   levels   of   indirection   from   'char   [3] '
Program6\FmodelDlg.cpp(272)   :   error   C2146:   syntax   error   :   missing   ') '   before   identifier   'len '
执行   cl.exe   时出错.

m_strPath1[100],是已经定义好的一个全局变量,接收文件路径。我主要是想把一个文件路径,比如c:\abcd\Debug\abcd.exe,转换为c:\abcd\Debug\result.txt;但运行时出错。
可能问题很简单,但是我实在解决不了,哪位帮忙,谢谢。

[解决办法]
int len;
len=strlen(m_strPath1);
while(m_strPath1[len]!= "\ ")
--len;
strcat(m_strPath1, "result.txt ");
-----------------------------------??
楼主可能要的是这个吧:
int len = strlen(m_strPath1)-1;
while(len> 0&&m_strPath1[len] != '\\ ')
--len;
char *p = m_strPath1+len+1;
strcpy(p, "result.txt ");

热点排行