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 ");