delphi->BCB,谢谢!
var fp:textfile;
str:String;
begin
str2:='abc';
//写文件
assignfile(fp, 'c:\abc.txt');
rewrite(fp);
writeln(fp, 'this is the firstline');
writeln(fp, 'this is the secondline');
closefile(fp);
//读文件
assignfile(fp, 'C:\abc.txt');
reset(fp);
readln(fp, str);
showmessage(str);
closefile(fp);
end;
问题点数:20、回复次数:5Top
1 楼victorchen_2000(微力)回复于 2001-08-09 14:23:26 得分 20
char str2[256];
FILE *fp;
fp=fopen("abc.txt","w+");
if (fp==NULL) return;
fprintf(fp,"this is the first..");
fprintf(fp,"this is the sec..");
fclose(fp);
fp=fopen("abc.txt","r");
fgets(fp,str2);
fclose(fp);Top
2 楼chime(chime)回复于 2001-08-09 14:34:15 得分 0
?Top
3 楼chime(chime)回复于 2001-08-09 15:02:28 得分 0
谢谢victorchen_2000(微力),待会给分。
fprintf不支持变量吗?
AnsiString title;
title"<name>";
fprintf(fp,title);//出错Top
4 楼chime(chime)回复于 2001-08-09 15:34:51 得分 0
FILE *stream;
int i = 100;
char c = 'C';
float f = 1.234;
/* open a file for update */
stream = fopen("c:\\abc.txt", "w+");
/* write some data to the file */
fprintf(stream, "%d %c %f", i, c, f);
/* close the file */
fclose(stream);
以上可写入变量,但如果我要写入的变量是一大串字符则写出来是%号,如何处理?(加分!)
以下写出后abc.txt是空的:
FILE *stream;
WideString c ="sdfsjdfjsdsdffs";
/* open a file for update */
stream = fopen("c:\\abc.txt", "w+");
/* write some data to the file */
fprintf(stream, "%c",c);
/* close the file */
fclose(stream);Top
5 楼victorchen_2000(微力)回复于 2001-08-15 13:19:06 得分 0
fprintf(stream,"%s",c);
是%s,不是%cTop




