CString str="d:\\myjob\\test.txt",str1; int n=str.ReverseFind('\\'); int Len=str.GetLength(); str1=str.Mid(n+1,Len-n); AfxMessageBox(str1); str1为"test.txt"
CStdioFile m_file; //open file m_file.open(strfilename,CFile::modeRead);//read string of one line from file CString str; m_file.ReadString(str);//str 怎么将值赋给P char *p; p=new char[str.Getlength()]; strcpy(p,str);
CString m_disp;
myfile.Open("d:\\myjob\\test.txt",CFile::modeRead);
myfile.SeekToBegin();
myfile.Read(m_disp.GetBufferSetLength(myfile.GetLength()),myfile.GetLength());
strcpy(exeFullPath,"d:\\myjob\\test.txt");
//分离全路径为驱动、程序目录
_splitpath(exeFullPath,szDirve,szDir,NULL,NULL);
CString m_sFullPath=exeFullPath;
CString m_filename=m_sFullPath.Right(strlen(exeFullPath)-strlen(szDir)-strlen(szDirve));
//测试结果就是你要求的
int n=str.ReverseFind('\\');
int Len=str.GetLength();
str1=str.Mid(n+1,Len-n);
AfxMessageBox(str1);
str1为"test.txt"
int nPos = str.ReverseFind('\\')
str = str.Right(str.GetLength()-nPos);
int pos=str.ReverseFind('\\');
CString result;
LPTSTR p=str.GetBuffer(str.GetLength());
result= p+pos+1 ;
MessageBox(result);
int pos= str.ReverseFind('\\');
CString result= str.Right(str.GetLength()-pos-1);
MessageBox(result);
TCHAR exeFullPath[MAX_PATH];
strcpy(exeFullPath,m_sPathName);//设m_sPathName="d:\myjob\test.txt"
//分离全路径为驱动、程序目录
_splitpath(exeFullPath,szDirve,szDir,NULL,NULL);
CString m_sFullPath=exeFullPath;
CString m_filename=m_sFullPath.Right(strlen(exeFullPath)-strlen(szDir)-strlen(szDirve));
//m_filename就是文件名
怎么将一个文件中的一行字符串赋给 str ?
然后
char * p;
str 怎么将值赋给P?
给你的很好用
//open file
m_file.open(strfilename,CFile::modeRead);//read string of one line from file
CString str;
m_file.ReadString(str);//str 怎么将值赋给P
char *p;
p=new char[str.Getlength()];
strcpy(p,str);
怎么将一个文件中的一行字符串赋给 str ?
然后
char * p;
str 怎么将值赋给P?
------------------
CString由于重载了=和LPSTR,
因此可以直接用char*作为构造函数初始化参数
比如 CString str("abc");
或者 CString str;
str="abc";均可至于赋值,直接 char *p=str.GetBuffer();即可
然后从这个地方开始复制,如果要分离,把该地方的'\\'='\0'strcpy(target,&sour[pos]);