一个关于文件读写的问题!谢谢!【入门级】

ymlianming 2003-05-17 07:53:10
我用mfc
写了个小程序
我想实现一下功能:我的一个button可以保存5个edit的内容在当前目录下
另一个button可以读取保存在ini内的内容
可是如何保存在当前目录?
还有就是如何一行一行的读取ini的内容?
...全文
30 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
Skt32 2003-05-17
  • 打赏
  • 举报
回复
如何一行一行读入文本文件
http://codeguru.earthweb.com/files/StringFile.zip
Skt32 2003-05-17
  • 打赏
  • 举报
回复
1. GetCurrentDirectory
GetCurrentDirectory
The GetCurrentDirectory function retrieves the current directory for the current process.

DWORD GetCurrentDirectory(
DWORD nBufferLength, // size of directory buffer
LPTSTR lpBuffer // directory buffer
);
Parameters
nBufferLength
[in] Specifies the length, in TCHARs, of the buffer for the current directory string. The buffer length must include room for a terminating null character.
lpBuffer
[out] Pointer to the buffer that receives the current directory string. This null-terminated string specifies the absolute path to the current directory.
Return Values
If the function succeeds, the return value specifies the number of characters written to the buffer, not including the terminating null character.

If the function fails, the return value is zero. To get extended error information, call GetLastError.

If the buffer pointed to by lpBuffer is not large enough, the return value specifies the required size of the buffer, including the number of bytes necessary for a terminating null character.

Requirements
Windows NT/2000: Requires Windows NT 3.1 or later.
Windows 95/98: Requires Windows 95 or later.
Header: Declared in Winbase.h; include Windows.h.
Library: Use Kernel32.lib.
Unicode: Implemented as Unicode and ANSI versions on Windows NT/2000.

See Also
File I/O Overview, File I/O Functions, CreateDirectory, GetSystemDirectory, GetWindowsDirectory, RemoveDirectory, SetCurrentDirectory

2.

用于INI文件读取的CIniFile类 详细信息 < INI文件 >

功能强大的CIniFile类。可以修改、读取变量的值。也可以加入新的变量新的组。

[代码性质] VC可重用代码段
[代码作者] 阿皮
[文件大小] 5K
[更新日期] 2003-1-6 19:11:00
[下载次数] 2134
http://www.vckbase.com/code/downcode.asp?id=1736

qinghero 2003-05-17
  • 打赏
  • 举报
回复
用CFile类
(1)
open方法
CFile f;
CFileException e;
char* pFileName = "test.dat";
if( !f.Open( pFileName, CFile::modeCreate | CFile::modeWrite, &e ) )
{
#ifdef _DEBUG
afxDump << "File could not be opened " << e.m_cause << "\n";
#endif
}
这样就保存在当前的目录了

(2) 用read方法,每次读一个字符,直到这个字符是'\n',这样就可以退出while
然后对这个字符串分析

char pbuf[100];
char* p=pbuf;
UINT nBytesRead = f.Read( p, 1 );
while(*p!='\n')
{
p++;
f.Read(p,1)
}
*p=0;
然后就可以对这一样进行处理了




16,471

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC相关问题讨论
社区管理员
  • 基础类社区
  • Web++
  • encoderlee
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

        VC/MFC社区版块或许是CSDN最“古老”的版块了,记忆之中,与CSDN的年龄几乎差不多。随着时间的推移,MFC技术渐渐的偏离了开发主流,若干年之后的今天,当我们面对着微软的这个经典之笔,内心充满着敬意,那些曾经的记忆,可以说代表着二十年前曾经的辉煌……
        向经典致敬,或许是老一代程序员内心里面难以释怀的感受。互联网大行其道的今天,我们期待着MFC技术能够恢复其曾经的辉煌,或许这个期待会永远成为一种“梦想”,或许一切皆有可能……
        我们希望这个版块可以很好的适配Web时代,期待更好的互联网技术能够使得MFC技术框架得以重现活力,……

试试用AI创作助手写篇文章吧