[Plugin] [REL]fstream - Printable Version
+- SA-MP Forums Archive (
https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (
https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Plugin Development (
https://sampforum.blast.hk/forumdisplay.php?fid=18)
+--- Thread: [Plugin] [REL]fstream (
/showthread.php?tid=356154)
[REL]fstream -
Terminator3 - 02.07.2012
Simple plugin that adds functionality fstream library to PAWN
What is fstream?
http://www.cplusplus.com/reference/iostream/fstream/
Functions:
fstream:Fopen(filename[], mode, bool:scriptfiles = true)
Opens/creates the file
- filename[] - file name
- mode - mode to open, example (ios::in) (ios::out|ios::in)
- bool:scriptfiles = true - if true files will be opened / created in scriptfiles folder, if false in server folder
Return the ID of file, You can open the 32 files at once. if the error arose will return -1
How to check if file was open correctly?
pawn Code:
new fstream:file = Fopen("file.txt", ios::out);
if(_:file != -1)
//or
if(file != fstream:(-1))
Fclose(fstream:file, bool:clear = true)
Closes the file
- fstream:file - file id returned by Fopen
- bool:clear = true - whether or not cleaned after closing the file id, default yes
Returns nothing
Fcopyfmt(fstream:file, fstream:file2)
Copies the contents of one file to another
- fstream:file - id file, into which something is copied
- fstream:file2 - id file from which something is copied
Returns nothing
Fgetchar(fstream:file)
gets one character from a file, is equivalent to the
get function with no arguments
Returns the character from a file
Functions:
Fisopen(fstream:file)
Ftellp(fstream:file)
Ftellg(fstream:file)
Fbad(fstream:file)
Ffail(fstream:file)
Fgood(fstream:file)
Feof(fstream:file)
Fgcount(fstream:file)
Fpeek(fstream:file)
Fsync(fstream:file)
Freadsome(fstream:file, dest[], size)
Fnarrow(fstream:file, c, dfault = NULL)
Fwiden(fstream:file, c)
Fwidth(fstream:file, c = NO_ARG)
Ffill(fstream:file, c = NO_ARG)
Fflags(fstream:file, mask = NO_ARG)
Fsetf(fstream:file, fmtfl, mask = NO_ARG)
Frdstate(fstream:file)
These are the same as in C + +, that is the same act and the same return
Functions:
Fclear(fstream:file, flag = ios::goodbit)
Fseekp(fstream:file, fpos = 0, mode = NO_ARG)
Fseekg(fstream:file, fpos = 0, mode = NO_ARG)
Funget(fstream:file)
Fflush(fstream:file)
Fput(fstream:file, c)
Fget(fstream:file, dest[], size = sizeof dest, delim = '\n')
Fgetline(fstream:file, dest[], size = sizeof dest, delim = '\n')
Fread(fstream:file, dest[], size)
Fignore(fstream:file, size = 1, delim = EOF)
Fputback(fstream:file, fpos)
Funsetf(fstream:file, mask)
Fsetstate(fstream:file, flag)
Same as above but do not return
Fexceptions(fstream:file, except = NO_ARG)
By default, it returns as a C + + with the modified argument does not return
Fwrite(fstream:file, const str[], size = NO_ARG)
Why here is size = NO_ARG? it is clear that's you going to use here strlen, that's why I do this already in the plugin
Function returns nothing
Which means NO_ARG?
Functions in fstream sometimes have the same name but different arguments and action. That is why I added a macro with a value of -2 means use that function without this argument
Example of constans from C++
Code:
ios::showpos
ios::hexfloat
ios::beg
ios::trunc
ios::badbit
Can I use C++ style like
plik.write("text")
plik.ignore(true)
itp.?
Yes but before you have to give
F:
pawn Code:
F:plik.write("text");
if(F:plik.ignore(true))
etc.
Update #1:
Thanks to ****** now you can save data to a file in a very simple way:
pawn Code:
new fstream::file("test.txt", ios::out);
file = file + S("string/text here") + 20 + 18.5325 + C('A') + endl;
Fclose(file);
in file will be
Quote:
string/text here2018.5325A
//empty line
|
and one more example
pawn Code:
file = file + S("Money = ") + GetPlayerMoney(playerid) + endl + S("Score = ") + GetPlayerScore(playerid) + endl;
in file will be
Quote:
Money = 1000
Score = 10
//empty line
|
S() - if you want to save string in file
C() - if you want to save one char in file
endl - if you want to save enter in file (it's just \n char, fstream change it to \r\n)
DOWNLOAD; Mirror
Source Code; Mirror
Re: [REL]fstream -
Niko_boy - 02.07.2012
owwa another file system to SA:MP
Cool
Re: [REL]fstream -
Terminator3 - 02.07.2012
Oh, nice, but i do not understand callback _fstream_Fwrite_fix()
for what it's needed?
Re: [REL]fstream -
Terminator3 - 02.07.2012
Should not be like that?
pawn Code:
forward
_fstream_Fwrite_fix();
public
_fstream_Fwrite_fix()
{
Fwrite(fstream:(-1), "");
}
because bad id file here is not 0 only -1
Re: [REL]fstream -
Terminator3 - 06.07.2012
@****** is one big problem with your code, Fwrite takes 3 arguments, the last must be -2, with your code 3 argument has a value 16436
Can you fix it because I do not know much about the EMIT
p.s I added
pawn Code:
stock char_tag:
C(val)
{
return char_tag:val;
}
stock fstream:
operator+(
fstream:fhnd,
char_tag:val)
{
Fput(fhnd, val);
return fhnd;
}
Re: [REL]fstream -
sampplayer12 - 06.07.2012
Good Work