void Append_file_to_file(char *inputPath, char *outputPath) { qint64 BUFFER_SIZE = 10*1024*1024; qint64 buffer_len = 0; QFile inputfile(inputPath); if (!inputfile.open(QIODevice::ReadOnly)) return; QFile outputfile(outputPath); if (!outputfile.open(QIODevice::WriteOnly | QIODevice::Append)) return; QDataStream inputstream(&inputfile); QDataStream outputstream(&outputfile); char* buffer = new char[BUFFER_SIZE]; while(!inputstream.atEnd()) { buffer_len = inputstream.readRawData( buffer, BUFFER_SIZE ); outputstream.writeRawData( buffer, buffer_len ); } inputfile.close(); outputfile.close(); delete[] buffer; return; }
void writeMatrixToCsv(Eigen::Matrix<T,Eigen::Dynamic,Eigen::Dynamic> paramMatrix,const std::string &path) { std::ofstream outputstream (path,std::ofstream::out); // 682 if(outputstream.is_open()) { for(int i = 0; i < paramMatrix.rows(); i++) { outputstream << paramMatrix(i,0); for(int j = 1; j < 11; j++) { outputstream << " " << j << ":" << paramMatrix(i,j); } outputstream << endl; } outputstream.close(); } else { cout << "Unable to write into CSV" << endl; } }
void Log::createLogFile(const std::string &path){ ofstream outputstream(path.c_str(), ios::app); if (outputstream.is_open() ) { m_logFile = path; if (logCache.size() > 0 ) { // writes the content of the cache into the new file outputstream << logCache ; // cleans the cache logCache = string(""); } outputstream.close ( ); } else { if ( dbgLevel >= WMSLOG_WARNING ){ errMsg (WMS_WARNING, "I/O error", "unable to open the logfile: " + path , true); m_logFile = ""; } } }
bool ControllerPresetFileHandler::writeDocument(QDomDocument root, const QString fileName) const { // Need to do this on Windows QDir directory; if (!directory.mkpath(fileName.left(fileName.lastIndexOf("/")))) { return false; } // FIXME(XXX): This is not the right way to replace a file (O_TRUNCATE). The // right thing to do is to create a temporary file, write the output to // it. Delete the existing file, and then move the temporary file to the // existing file's name. QFile output(fileName); if (!output.open(QIODevice::WriteOnly | QIODevice::Truncate)) { return false; } // Save the DOM to the XML file QTextStream outputstream(&output); root.save(outputstream, 4); output.close(); return true; }