PTypes is a simple alternative to the STL that includes multithreading and networking. It defines dynamic strings, character sets, lists and other basic data types along with threads, synchronization primitives, named pipes and IP sockets.
The following example demonstrates how to use PTypes streams to write to a file .
stream.cpp
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 | /**
* Simple example to write to a file
*/
#include <melikyan/ptypes/include/pstreams.h>
#include <melikyan/ptypes/include/pport.h>
using namespace pt;
int main() {
const char* fname = "stmtest.txt";
outfile f(fname,false);
f.set_bufsize(1024); // the default value in this version is 8192
try {
f.open();
f.put("This is a test file.\n");
f.close();
} catch (estream* e) {
perr.putf(e->get_message());
delete e;
}
return 0;
}
|
Create a block:
$ bii init my_project
$ cd my_project
$ bii open examples/ptypes
Compile stream.cpp
file:
$ bii build
Now you can run it and check it generates a file:
$ cd bin
$ ./examples_ptypes_stream
This creates a stmtest.txt
file with something written inside. Just open it and you’ll see its content:
This is a test file
Any doubts? Do not hesitate to contact us visit our forum and feel free to ask any questions.