本文整理汇总了C++中ofstream::is_open方法的典型用法代码示例。如果您正苦于以下问题:C++ ofstream::is_open方法的具体用法?C++ ofstream::is_open怎么用?C++ ofstream::is_open使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ofstream
的用法示例。
在下文中一共展示了ofstream::is_open方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: getFileModeCallback
void getFileModeCallback(const std_msgs::String::ConstPtr& msg)
{
std::string temp = msg->data;
if( "write" == temp )
{
if( !tactileDataFile.is_open() && !jointsDataFile.is_open() )
{
std::cout << "\n\n ===== Creating files: " << tactileFileName << " and " << jointsFileName;
tactileDataFile.open(tactileFileName.c_str());
jointsDataFile.open(jointsFileName.c_str());
writeStatus = true;
}
}
else
{
if( tactileDataFile.is_open() && jointsDataFile.is_open() )
{
std::cout << "\n\n ===== Closing files: " << tactileFileName << " and " << jointsFileName;
tactileDataFile.close();
jointsDataFile.close();
writeStatus = false;
}
}
std::cout << "\n\n ===== mode: " << msg->data;
}
示例2: flush_debug
/* Flushes all ostreams used for debug messages. You need to call
this before forking. */
void flush_debug()
{
if (logfile_null.is_open())
logfile_null.flush();
if (logfile_file.is_open())
logfile_file.flush();
}
示例3: close
virtual
void
close()
{
if(paramFile_.is_open()) paramFile_.close();
if(occFile_.is_open()) occFile_.close();
}
示例4: OpenLogFiles
BOOL OpenLogFiles()
{
// Open import log file
if ( FileSize("./log/import.log") > MAXLOGSIZE )
// Truncate before writing
logfile.open("./log/import.log", ios::out);
else
// Append to existing
logfile.open("./log/import.log", ios::app);
if ( !logfile.is_open() )
{
cerr << "Could not open 'import.log'" << endl;
return FALSE;
}
// Open import error file
if ( FileSize("./log/import.err") > MAXERRSIZE )
// Truncate before writing
errfile.open("./log/import.err", ios::out);
else
// Append to existing
errfile.open("./log/import.err", ios::app);
if ( !errfile.is_open() )
{
cerr << "Could not open 'import.err'" << endl;
return FALSE;
}
return TRUE;
}
示例5: openFiles
// Open the various files for output
bool DataScaling::openFiles(ifstream& kaggleFile, ofstream& nodeFile, ofstream& edgeFile, ofstream& adFile)
{
kaggleFile.open(this->kaggleFile);
if (!kaggleFile.is_open())
{
cout << "Failed to open input kaggle file:" << this->kaggleFile << endl;
return(false);
}
nodeFile.open(this->nodeFile);
if (!nodeFile.is_open())
{
cout << "Failed to open output node file:" << this->nodeFile << endl;
return(false);
}
edgeFile.open(this->edgeFile);
if (!edgeFile.is_open())
{
cout << "Failed to open output edge file:" << this->edgeFile << endl;
return(false);
}
adFile.open(this->adFile);
if (!adFile.is_open())
{
cout << "Failed to open output ad file:" << this->adFile << endl;
return(false);
}
return(true);
}
示例6: incomingData
void incomingData(Stream *stream)
{
Message *message = Message::receive(stream);
UserMessage *userMessage = dynamic_cast<UserMessage *>(message);
if (userMessage)
{
if (userMessage->type == eventId)
{
double elapsedTime = (double)startingTime.msecsTo(QTime::currentTime()) / 1000.;
if (outputFile.is_open())
outputFile << elapsedTime;
timeStamps.push_back(elapsedTime);
for (size_t i = 0; i < values.size(); i++)
{
if (i < userMessage->data.size())
{
if (outputFile.is_open())
outputFile << " " << userMessage->data[i];
values[i].push_back(userMessage->data[i]);
}
else
{
if (outputFile.is_open())
outputFile << " " << 0;
values[i].push_back(0);
}
}
if (outputFile.is_open())
outputFile << endl;
replot();
}
}
delete message;
}
示例7: output_converseved_quantities
/**
* Output the energy/angular momentum.
*/
void output_converseved_quantities(double E1, double L1, ofstream& output_file_energy, ofstream& output_file_angular_momentum) {
if (output_file_energy.is_open()) {
output_file_energy << E1 << endl;
}
if (output_file_angular_momentum.is_open()) {
output_file_angular_momentum << L1 << endl;
}
}
示例8: close_lattice_files
/**
* Close the files in case they are open
* @param scores_file the scores file
* @param lattice_file the lattice file
*/
inline void close_lattice_files(ofstream & scores_file, ofstream & lattice_file) const {
if (scores_file.is_open()) {
scores_file.close();
}
if (lattice_file.is_open()) {
lattice_file.close();
}
}
示例9:
~Disassembler(){
if (disassembly.is_open()){
disassembly.close();
}
if (simulation.is_open()){
simulation.close();
}
};
示例10: Load
public: void Load(physics::ModelPtr _model, sdf::ElementPtr _sdf){
world = _model->GetWorld();
model = _model;
trunk = model->GetLink("trunk");
#if(PRINT_DEBUG)
cout << "Loading the velocity over time plugin" << endl;
#endif
connection = event::Events::ConnectWorldUpdateBegin(boost::bind(&VelocityOverTimePlugin::worldUpdate, this));
// Get the name of the folder to store the result in
const char* resultsFolder = std::getenv("RESULTS_FOLDER");
if(resultsFolder == nullptr){
cout << "Results folder not set. Using current directory." << endl;
resultsFolder = "./";
}
{
const string resultsXFileName = string(resultsFolder) + "/" + "velocities_x.csv";
bool exists = boost::filesystem::exists(resultsXFileName);
outputCSVX.open(resultsXFileName, ios::out | ios::app);
assert(outputCSVX.is_open());
if (!exists) {
writeHeader(outputCSVX);
}
}
{
const string resultsYFileName = string(resultsFolder) + "/" + "velocities_y.csv";
bool exists = boost::filesystem::exists(resultsYFileName);
outputCSVY.open(resultsYFileName, ios::out | ios::app);
assert(outputCSVY.is_open());
if (!exists) {
writeHeader(outputCSVY);
}
}
{
const string resultsZFileName = string(resultsFolder) + "/" + "velocities_z.csv";
bool exists = boost::filesystem::exists(resultsZFileName);
outputCSVZ.open(resultsZFileName, ios::out | ios::app);
assert(outputCSVZ.is_open());
if (!exists) {
writeHeader(outputCSVZ);
}
}
// Write out t0
outputCSVX << "Velocity X (m/s), " << trunk->GetWorldCoGLinearVel().x << ", ";
outputCSVY << "Velocity Y (m/s), " << trunk->GetWorldCoGLinearVel().y << ", ";
outputCSVZ << "Velocity Z (m/s), " << trunk->GetWorldCoGLinearVel().z << ", ";
}
示例11: output_orbital_parameters
/**
* Output the excentric/great half axis to a file.
*/
void output_orbital_parameters(double a1, double e1, ofstream& output_file_a, ofstream& output_file_e) {
if (output_file_a.is_open()) {
output_file_a << a1 << endl;
}
if (output_file_e.is_open()) {
output_file_e << e1 << endl;
}
}
示例12: shared_print
void shared_print(string id, int value) {
if (!f.is_open()) { // lazy initialization -- A
std::unique_lock<mutex> locker(m_mutex);
if (!f.is_open()) {
f.open("log.txt"); // This must be synchronized -- B
}
}
f << "From " << id << ": " << value << endl; // I don't care this is not synchronized
}
示例13: close_debug
void close_debug()
{
if (logfile_null.is_open())
logfile_null.close();
if (logfile_file.is_open())
logfile_file.close();
logfile_trace = logfile_info = logfile_warning = logfile_error = 0;
}
示例14: OpenOutputFile
void OpenOutputFile(){
static string _FileNumber = "";
if (!OutputFile.is_open() || _FileNumber != FileNumber){
_FileNumber = FileNumber;
if (OutputFile.is_open()){
OutputFile.close();
}
string file = "output_" + FileNumber + ".txt";
cout << "Opening output file...";
OutputFile.open(file.c_str(), ios::ate | ios::app | ios::out);
if (!OutputFile){
TerminateError("Unable to open output file.");
}
}
}
示例15: main
int main(int argc, char **argv)
{
for(;;) {
int c;
int option_index = 0;
static struct option long_options[] = {
{"offset", 1, 0, 'o'},
{"help", 0, 0, 'h'},
{0, 0, 0, 0},
};
c = getopt_long(argc, argv, "ho:", long_options, &option_index);
if(c == -1)
break;
switch(c) {
case 'o':
fileoffset = strtoul(optarg, NULL, 0);
printf("offset %#zx\n", fileoffset);
break;
case 'h':
default:
usage(argc, argv);
break;
}
}
if (argc - optind < 2) {
printf("not enough arguments\n");
usage(argc, argv);
}
inputfile = argv[optind++];
outputfile = argv[optind++];
printf("input file %s\n", inputfile.c_str());
printf("output file %s\n", outputfile.c_str());
iHex hex;
if (hex.Open(inputfile) < 0) {
fprintf(stderr, "error opening input file\n");
return 1;
}
out.open(outputfile.c_str(), ios::out|ios::trunc|ios::binary);
if (!out.is_open()) {
fprintf(stderr, "error opening output file\n");
return 1;
}
hex.SetCallback(&ihexcallback);
hex.Parse();
hex.Close();
out.close();
return 0;
}