CFILE C++获取当前路径 CSting 拼接
来源:互联网 发布:地理学软件 编辑:程序博客网 时间:2024/05/17 02:09
Accessing File Status
Home | Overview | How Do I
CFile also supports getting file status, including whether the file exists, creation and modification dates and times, logical size, and path.
To get file status
- Use the CFile class to get and set information about a file. One useful application is to use theCFile static member function GetStatus to determine if a file exists. GetStatus returns 0 if the specified file does not exist.
Thus, you could use the result of GetStatus to determine whether to use the CFile::modeCreateflag when opening a file, as shown by the following example:
CFile theFile; char* szFileName = "c:\\test\\myfile.dat"; BOOL bOpenOK; CFileStatus status; if( CFile::GetStatus( szFileName, status ) ) { // Open the file without the Create flag bOpenOK = theFile.Open( szFileName, CFile::modeWrite ); } else { // Open the file with the Create flag bOpenOK = theFile.Open( szFileName, CFile::modeCreate | CFile::modeWrite ); }
For related information
如果要是清空缓存 用
flush()即可
C++获取当前路径实现技巧分享
C++获取当前路径的实现方法有很多种,我们在这里搜罗了两个比较常用简单的方法供大家参考。希望能够让大家从中获得一些帮助。
AD:
C++编程语言在实际应用中,可以帮助开发人员轻松的实现各种功能与需求。比如在对文件的操作上就可以灵活的运用各种个方法来实现。那么接下来我们将会给大家介绍一下C++获取当前路径的相关实现方法。
C++获取当前路径相关实现代码示例:
1.以下代码来自CSDN 2004 VC编程经验总结.
- {
- CString strPath;
- GetCurrentDirectory(MAX_PATH,strPath.GetBuffer(MAX_PATH));
- strPath.ReleaseBuffer();
- return strPath;
- }
2.以下代码来自TZ MFC.NET Primer 1.01,
- CString CPropertyGridSampleApp::GetCurrWorkingDir()
- {
- CString strPath;
- TCHAR szFull[_MAX_PATH];
- TCHAR szDrive[_MAX_DRIVE];
- TCHAR szDir[_MAX_DIR];
- ::GetModuleFileName(NULL, szFull, sizeof(szFull)/sizeof(TCHAR));
- _tsplitpath(szFull, szDrive, szDir, NULL, NULL);
- _tcscpy(szFull, szDrive);
- _tcscat(szFull, szDir);
- strPath = CString(szFull);
- return strPath;
- }
使用第一段C++获取当前路径的代码可以获得应用程序运行时所在目录。但由于在使用Microsoft Visual Studio.NET编译并运行项目时,真正的宿主是IDE,所以当前目录是项目所在目录,并不是DEBUG或者RELEASE目录,这一点需要开发人员注意。而第二段代码可以动态解决此问题。并且增加了Unicode支持(TCHAR)。
CString sql= "select * from Str where SaveStr = '";
sql+=szPayerName;
sql+="' order by SaveStr";
只可以使用sql+=引号内字符串或者字符串变量。
不可以使用sql=引号内字符串或者字符串变量+引号内字符串或者字符串变量.
切记,切记!!!!
- CFILE C++获取当前路径 CSting 拼接
- C\C++ 获取当前路径
- C\C++ 获取当前路径
- C\C++ 获取当前路径
- C\C++获取当前路径
- C\C++ 获取当前路径
- c语言获取当前路径
- C/C++获取当前路径
- C获取当前程序路径, exe路径
- linux c++:获取程序当前路径
- 用C语言获取当前路径
- C\C++ 获取当前工作路径
- Linux C 获取当前进程可执行文件路径
- c语言获取当前工作路径(转)
- c语言获取当前工作路径(转)
- C语言获取当前工作路径
- c语言获取当前工作路径(转)
- c语言获取当前工作路径(转)
- linux 下安装oracle 10g
- Java:多线程等待所有线程结束(CountDownLatch/CyclicBarrier) .
- pyton设计一个函数,让返回值的调用来回切换,调用一次,返回1,下次调用返回0
- Angelababy代言《神魔》:不仅仅是打明星牌
- liunx中可重入和不可重入函数
- CFILE C++获取当前路径 CSting 拼接
- TCP/IP三次握手详解
- [Leetcode 25, hard] Reverse Nodes in k-Group
- 四件在我步入职业软件开发生涯那天起就该知道的事情
- android 开发网址
- Oracle 10g RMAN-视频分享
- MFC 多线程及线程同步
- linux创建新用户后shell无法自动补全命令
- 再谈ThinkPHP(1)----再次出发