g++ -std=c++17 -lstdc++fs -c main.cpp main.cpp: In function ‘int main()’:…
- User
g++ -std=c++17 -lstdc++fs -c main.cpp main.cpp: In function ‘int main()’: main.cpp:10:10: error: ‘std::filesystem’ has not been declared 10 | std::filesystem::path filePath(inputFilePath); | ^~~~~~~~~~ main.cpp:11:36: error: ‘std::filesystem’ has not been declared 11 | std::uintmax_t fileSize = std::filesystem::file_size(filePath); | ^~~~~~~~~~ main.cpp:11:58: error: ‘filePath’ was not declared in this scope 11 | std::uintmax_t fileSize = std::filesystem::file_size(filePath); | ^~~~~~~~ make: *** [Makefile:10: main.o] Error 1
nclude #include #include #include "stdio.h"
namespace assignment_2a { void reverse(){ // Print file size std::string inputFilePath; printf("Path to the file: "); std::cin >> inputFilePath; std::filesystem::path filePath(inputFilePath); std::uintmax_t fileSize = std::filesystem::file_size(filePath); printf("File size: %ju byte\n", fileSize); //Open file std::ifstream infile(inputFilePath, std::ios::binary | std::ios::in);
// Create array char* buffer = new char[fileSize]; // Write file to array infile.read(buffer, fileSize); infile.close(); // Reverse array for (std::uintmax_t i = 0; i < fileSize / 2; ++i) { std::swap(buffer[i], buffer[fileSize - 1 - i]); } std::string outFilePath = "out_"+inputFilePath; // Create output file std::ofstream outfile(outFilePath, std::ios::binary | std::ios::out); // Write reversed array to file outfile.write(buffer, fileSize); outfile.close(); // Clean memory delete[] buffer; printf("File reversed succesfully and writed to %s\n", outFilePath.c_str());} }
- Assistant
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.