| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1833 人关注过本帖
标题:关于vc++中的输入输出流,请教
只看楼主 加入收藏
luoxian_2003
Rank: 1
等 级:新手上路
威 望:2
帖 子:163
专家分:0
注 册:2006-2-22
收藏
 问题点数:0 回复次数:7 
关于vc++中的输入输出流,请教
再vc++中怎样写 file 菜单下的 save 和 open 的函数啊?
就像我现在要开发一个像 windows 里的 记事本 一样的软件,
非得要用到序列化吗》?
还有其他的途径吗?
望高手解决小弟的困惑,谢谢

[此贴子已经被作者于2006-5-22 21:48:02编辑过]

搜索更多相关主题的帖子: 输出 输入 
2006-05-22 21:28
vandy
Rank: 1
等 级:新手上路
帖 子:10
专家分:0
注 册:2006-5-15
收藏
得分:0 
要么你就用数据库ODBC
要么就用数据流!!!!
2006-05-22 22:17
myajax95
Rank: 16Rank: 16Rank: 16Rank: 16
等 级:版主
威 望:30
帖 子:2978
专家分:0
注 册:2006-3-5
收藏
得分:0 
最好别用序列化CArchive 的 Serilization会给你无限烦恼,除非你的数据结构从此一丝一毫都不变。这是微软设计VC时几乎最烂的一环。比较推荐的方法是自己写存档文件。如果不在乎文件大小可以存成XML格式,否则写成XML在压缩成binary。

http://myajax95./
2006-05-23 03:46
WindyGo
Rank: 1
等 级:新手上路
帖 子:26
专家分:0
注 册:2006-5-10
收藏
得分:0 

文档类可以基于CEditView
文件读取可以用CFile类,定义如下:
class CFile : public CObject
{
DECLARE_DYNAMIC(CFile)

public:
// Flag values
enum OpenFlags {
modeRead = 0x0000, //只读
modeWrite = 0x0001, //只写
modeReadWrite = 0x0002, //读写兼用
shareCompat = 0x0000,
shareExclusive = 0x0010,
shareDenyWrite = 0x0020, //非独占模式只写
shareDenyRead = 0x0030, //非独占模式只读
shareDenyNone = 0x0040,//非独占模式读写兼用
modeNoInherit = 0x0080,
modeCreate = 0x1000, //创建文件(不管有没有文件)
modeNoTruncate = 0x2000, //与modeCreate一起用,只有在没有文件时才创建文件
typeText = 0x4000, // typeText and typeBinary are used in
typeBinary = (int)0x8000 // derived classes only
};

enum Attribute {
normal = 0x00,
readOnly = 0x01,
hidden = 0x02,
system = 0x04,
volume = 0x08,
directory = 0x10,
archive = 0x20
};

enum SeekPosition { begin = 0x0, current = 0x1, end = 0x2 };

enum { hFileNull = -1 };

// Constructors
CFile();
CFile(int hFile);
CFile(LPCTSTR lpszFileName, UINT nOpenFlags);

// Attributes
UINT m_hFile;
operator HFILE() const;

virtual DWORD GetPosition() const;
BOOL GetStatus(CFileStatus& rStatus) const;
virtual CString GetFileName() const;
virtual CString GetFileTitle() const;
virtual CString GetFilePath() const;
virtual void SetFilePath(LPCTSTR lpszNewName);

// Operations
virtual BOOL Open(LPCTSTR lpszFileName, UINT nOpenFlags,
CFileException* pError = NULL);

static void PASCAL Rename(LPCTSTR lpszOldName,
LPCTSTR lpszNewName);
static void PASCAL Remove(LPCTSTR lpszFileName);
static BOOL PASCAL GetStatus(LPCTSTR lpszFileName,
CFileStatus& rStatus);
static void PASCAL SetStatus(LPCTSTR lpszFileName,
const CFileStatus& status);

DWORD SeekToEnd();
void SeekToBegin();

// backward compatible ReadHuge and WriteHuge
DWORD ReadHuge(void* lpBuffer, DWORD dwCount);
void WriteHuge(const void* lpBuffer, DWORD dwCount);

// Overridables
virtual CFile* Duplicate() const;

virtual LONG Seek(LONG lOff, UINT nFrom);
virtual void SetLength(DWORD dwNewLen);
virtual DWORD GetLength() const;

virtual UINT Read(void* lpBuf, UINT nCount);
virtual void Write(const void* lpBuf, UINT nCount);

virtual void LockRange(DWORD dwPos, DWORD dwCount);
virtual void UnlockRange(DWORD dwPos, DWORD dwCount);

virtual void Abort();
virtual void Flush();
virtual void Close();

// Implementation
public:
virtual ~CFile();
#ifdef _DEBUG
virtual void AssertValid() const;
virtual void Dump(CDumpContext& dc) const;
#endif
enum BufferCommand { bufferRead, bufferWrite, bufferCommit, bufferCheck };
virtual UINT GetBufferPtr(UINT nCommand, UINT nCount = 0,
void** ppBufStart = NULL, void** ppBufMax = NULL);

protected:
BOOL m_bCloseOnDelete;
CString m_strFileName;
};
偷懒点可以不用CFile,用
int fclose (FILE *stream);
int fflush (FILE *stream);
int fgetc (FILE *stream);
int fgetpos (FILE *stream, fpos_t *pos);
char *fgets (char *s, int n, FILE *stream);
FILE *fopen (const char *path, const char *mode);
int fprintf (FILE *stream, const char *format, ...);
int fputc (int c, FILE *stream);
int fputs (const char *s, FILE *stream);
size_t fread (void *ptr, size_t size, size_t n, FILE *stream);
FILE *freopen (const char *path, const char *mode,
FILE *stream);
int fscanf (FILE *stream, const char *format, ...);
int fseek (FILE *stream, long offset, int whence);
int fsetpos (FILE *stream, const fpos_t *pos);
long ftell (FILE *stream);

[此贴子已经被作者于2006-6-10 8:24:58编辑过]


2006-05-23 16:14
luoxian_2003
Rank: 1
等 级:新手上路
威 望:2
帖 子:163
专家分:0
注 册:2006-2-22
收藏
得分:0 

感谢各位大大的指导


天地有正气,凛烈万古存。
2006-05-23 22:22
luoxian_2003
Rank: 1
等 级:新手上路
威 望:2
帖 子:163
专家分:0
注 册:2006-2-22
收藏
得分:0 
怎么写存档文件,版主?

天地有正气,凛烈万古存。
2006-05-23 23:04
WindyGo
Rank: 1
等 级:新手上路
帖 子:26
专家分:0
注 册:2006-5-10
收藏
得分:0 

FILE* files;
fs=fopen("文件","w");/*控制字符“w”为只写,“r”为只读,“b”为二进制文件,可以混用。*/

CFile files;
file.open("文件",CFile::modeWrite);
/*部分模式可以混用,用“|”隔开。
CFile只能用于打开二进制文件(其实文本文件的基础也是二进制文件)*/

[此贴子已经被作者于2006-6-10 8:20:36编辑过]


2006-06-10 08:18
myajax95
Rank: 16Rank: 16Rank: 16Rank: 16
等 级:版主
威 望:30
帖 子:2978
专家分:0
注 册:2006-3-5
收藏
得分:0 
查一查CArchive类的说明,那里有直接用File-->Open之后读写的方法。或者你只有File-->Open得到一个文件名,然后用C/C++的FILE*或者fstream自己写。

http://myajax95./
2006-06-11 23:34
快速回复:关于vc++中的输入输出流,请教
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.015293 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved