Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <cstdio>
- #include <iostream>
- #include <string>
- void write_to_file(const char* filename,
- const char* str) {
- FILE* pfile = nullptr;
- fopen_s(&pfile, filename, "a");
- if (pfile != nullptr) {
- fprintf(pfile,"%\n", str);
- fclose(pfile);
- printf("%s\n", "Job done.");
- }
- else {
- printf("%s\n","Can not open the file.");
- }
- }
- void write_to_binfile(
- const char* filename,
- const int* arr,
- const int size
- ) {
- FILE* pfile = nullptr;
- fopen_s(&pfile, filename, "w");
- if (pfile != nullptr) {
- fwrite(arr, sizeof(arr[0]), size, pfile);
- //fprintf(pfile, "%\n", str);
- fclose(pfile);
- printf("%s\n", "Job done.");
- }
- else {
- printf("%s\n", "Can not open the file.");
- }
- }
- int main() {
- int arr[]{ 1,2,3,4,5 };
- write_to_binfile("text.dat", arr, 5);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement