佳礼资讯网

 找回密码
 注册

ADVERTISEMENT

查看: 1425|回复: 9

请问下要怎样 read and write from text file ... (C++)

[复制链接]
发表于 29-7-2008 09:51 PM | 显示全部楼层 |阅读模式
请问下要怎样 read and write from text file ...
有哪位高手可以给一个 example ...
只需要 read and write from text file 就可以了 ...

因为偶需要做到 create new user,然后 login 的时候需要 type password ...

[ 本帖最后由 D-Strike 于 30-7-2008 12:07 AM 编辑 ]
回复

使用道具 举报


ADVERTISEMENT

发表于 29-7-2008 11:46 PM | 显示全部楼层
你要用哪一种programming language
回复

使用道具 举报

 楼主| 发表于 30-7-2008 12:07 AM | 显示全部楼层
原帖由 lewisksh 于 29-7-2008 11:46 PM 发表
你要用哪一种programming language


C++ 的。。。
谢谢。。。
回复

使用道具 举报

发表于 30-7-2008 11:03 AM | 显示全部楼层
C++的一般都是用stream的吧?沿用C的 fopen / fread / fwrite / fclose 也是可以的。
回复

使用道具 举报

 楼主| 发表于 30-7-2008 08:24 PM | 显示全部楼层
原帖由 geekman 于 30-7-2008 11:03 AM 发表
C++的一般都是用stream的吧?沿用C的 fopen / fread / fwrite / fclose 也是可以的。


就素不会用 ...
可以给一些 example 吗 ???
回复

使用道具 举报

发表于 31-7-2008 02:54 PM | 显示全部楼层
这是我用Turbo C++ Explorer (C++ Builder 2006) 写的:
  1. //---------------------------------------------------------------------------
  2. #include <vcl.h>
  3. #include <stdio.h>
  4. #include <conio.h>
  5. #include <iostream.h>
  6. #pragma hdrstop

  7. #pragma argsused
  8. int main(int argc, char* argv[])
  9. {
  10.         char buffer[255];

  11.         memset(buffer, 0, 255);

  12.         TFileStream *fs = new TFileStream("textfile.txt", fmOpenReadWrite);

  13.         fs->Read(buffer, 10);
  14.         cout << buffer;

  15.         strcpy(buffer, "This text is appended to the end of text file");
  16.         fs->Seek(0, soFromEnd);
  17.         fs->Write(buffer, strlen(buffer));

  18.         getch();
  19.         delete fs;
  20.         return 0;
  21. }
  22. //---------------------------------------------------------------------------
复制代码

[ 本帖最后由 geekman 于 31-7-2008 02:56 PM 编辑 ]
回复

使用道具 举报

Follow Us
 楼主| 发表于 31-7-2008 08:58 PM | 显示全部楼层
原帖由 geekman 于 31-7-2008 02:54 PM 发表
这是我用Turbo C++ Explorer (C++ Builder 2006) 写的://---------------------------------------------------------------------------
#include
#include
#include
#include
#pragma hdrstop

#pragm ...


可惜 visual c++  不能 run ...
因為 #include <vcl.h> #include <conio.h> 。。。。
學校只能用 visual c++ 而已 ...
其他的 program 的 coding 不能用 ...
因為偶們做了之后 coding 要 passup 給老師的 ...

[ 本帖最后由 D-Strike 于 31-7-2008 09:04 PM 编辑 ]
回复

使用道具 举报

发表于 1-8-2008 01:45 AM | 显示全部楼层
这只是个示范,编程语言万变不离其宗,更何况同为C++?VCL 是 Borland 自家的core library, 相当于VC++ 的MFC,stdio.h 在这个程式里并没有用到, 我放它在里面是因为自己的习惯,我每次写 console program 都会放这个 header 的。

这个示范已经向你展示如何使用 FileStream 的 Read() 和 Write(),如何把它转换成 VC++ 的版本,自己摸索吧。
回复

使用道具 举报


ADVERTISEMENT

发表于 15-8-2008 12:08 AM | 显示全部楼层
http://www.cplusplus.com/doc/tutorial/files.html

这里有tutorial, 可以慢慢学。
回复

使用道具 举报

 楼主| 发表于 16-8-2008 01:10 AM | 显示全部楼层
原帖由 evo9 于 15-8-2008 12:08 AM 发表
http://www.cplusplus.com/doc/tutorial/files.html

这里有tutorial, 可以慢慢学。

多謝 ...
偶已經做到了 ...
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

 

ADVERTISEMENT



ADVERTISEMENT



ADVERTISEMENT

ADVERTISEMENT


版权所有 © 1996-2023 Cari Internet Sdn Bhd (483575-W)|IPSERVERONE 提供云主机|广告刊登|关于我们|私隐权|免控|投诉|联络|脸书|佳礼资讯网

GMT+8, 23-12-2025 10:35 PM , Processed in 0.125316 second(s), 24 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表