02.07.2012, 16:00
(
Last edited by Terminator3; 07/07/2012 at 10:09 AM.
)
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
How to check if file was open correctly?
Fclose(fstream:file, bool:clear = true)
Closes the file
Fcopyfmt(fstream:file, fstream:file2)
Copies the contents of one file to another
Fgetchar(fstream:file)
gets one character from a file, is equivalent to the get function with no arguments
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++
Can I use C++ style like
plik.write("text")
plik.ignore(true)
itp.?
Yes but before you have to give F:
etc.
Update #1:
Thanks to ****** now you can save data to a file in a very simple way:
in file will be
and one more example
in file will be
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
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
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
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
Fgetchar(fstream:file)
gets one character from a file, is equivalent to the get function with no arguments
- fstream:file - file id
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
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))
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);
Quote:
string/text here2018.5325A //empty line |
pawn Code:
file = file + S("Money = ") + GetPlayerMoney(playerid) + endl + S("Score = ") + GetPlayerScore(playerid) + endl;
Quote:
Money = 1000 Score = 10 //empty line |
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