こんにちは、次のファイルにテキストを書き込もうとしています: ofstream
#include <iostream>
#include <fstream>
#include <sstream>
#include <string>
#include <cstring>
#include <stdlib.h>
using namespace std;
void init_log(ofstream* data_file, ofstream* incl_file, string algo){
stringstream datafilename;
datafilename << "report/data/" << algo << ".txt";
stringstream includefilename;
includefilename << "report/include/" << algo << ".tex";
data_file->open(datafilename.str().c_str(), ios::app);
incl_file->open(includefilename.str().c_str(), ios::app);
}
void write_log(ofstream* data_file, ofstream* incl_file, int size, double timesec){
stringstream tow_data;
tow_data << size << " " << timesec << endl;
stringstream tow_incl;
tow_incl << size << " & " << timesec << " \\\\ \\hline" << endl;
*data_file << tow_data.str().c_str();
*incl_file << tow_incl.str().c_str();
}
void close_log(ofstream* data_file, ofstream* incl_file){
data_file->close();
incl_file->close();
}
int main (int argc, const char * argv[]){
double elapsed = 1.0;
int test = 10;
ofstream* data_file;
ofstream* incl_file;
init_log(data_file, incl_file, "hello");
write_log(data_file, incl_file, text, elapsed);
close_log(data_file, incl_file);
return 0;
}
この XCode を実行すると、exec bad accesses がdata_file->open(datafilename.str().c_str(), ios::app);
? どこで間違っていますか?