/*------------------------------------------------------------------*\ author: m.gumz date: 040127 19:05:56 about: little demo howto use stringstreams stringstreams allow to work on strings the same way one work on files. for example one could open a stringstream and write to it -> the stringstream itself allocates enough memory to hold all the data. PROBLEM: work only with glibc (not win32 api) \*------------------------------------------------------------------*/ #include int main() { char* bp; size_t size; FILE* stream; /* get handle */ stream= open_memstream(&bp, &size); /* write into the stream, no need to alloc memory for bp */ fprintf(stream, "hello"); fflush(stream); printf("buf = `%s', size = %d\n", bp, size); fprintf(stream, ", world"); fclose(stream); printf("buf = `%s', size = %d\n", bp, size); return 0; }