#include#include using namespace std; int main() { ofstream outfile("example.txt"); int arr[5] = {1, 2, 3, 4, 5}; outfile.write(reinterpret_cast (arr), sizeof(arr)); outfile.close(); return 0; }
#includeIn this example, we use the ostringstream class to create a stream in memory and write the contents of a double array "values" to it. We first write the number of values to the stream followed by the values themselves using WritePointer. Finally, we extract the string from the stream and display it on the console. Package/library: Standard C++ library.#include using namespace std; int main() { ostringstream oss; double values[] = {3.14, 2.718, 1.414}; size_t sz = sizeof(values) / sizeof(values[0]); oss << sz << " "; oss.write(reinterpret_cast (values), sz * sizeof(double)); string output = oss.str(); cout << output << endl; return 0; }