I have the following cpp code and it output a file name called ‘output.txt(0,0)-(3,5)’. Is there a way to avoid single quote in the filename?
#include <iostream>
#include <fstream>
#include <string>
int main() {
// Define the filename as a std::string
std::string filename = "output.txt" + std::string("(0,0)-(3,5)");
// Open a file for writing using std::ofstream
std::ofstream outputFile(filename);
// Check if the file was opened successfully
if (outputFile.is_open()) {
// Write some data to the file
outputFile << "Hello, world!n";
outputFile << "This is a C++ program.n";
outputFile << "Writing to files is fun!n";
// Close the file
outputFile.close();
std::cout << "Data has been written to the file '" << filename << "' successfully.n";
} else {
// If the file couldn't be opened, print an error message
std::cerr << "Unable to open file '" << filename << "' for writing.n";
}
return 0;
}
3