ofstream

Very surprising perfs of fprintf vs std::ofstream (fprintf is very slow)

风格不统一 提交于 2020-01-01 05:07:27
问题 I was running some benchmarks to find the most efficient way to write a huge array to a file in C++ (more than 1Go in ASCII). So I compared std::ofstream with fprintf (see the switch I used below) case 0: { std::ofstream out(title, std::ios::out | std::ios::trunc); if (out) { ok = true; for (i=0; i<M; i++) { for (j=0; j<N; j++) { out<<A[i][j]<<" "; } out<<"\n"; } out.close(); } else { std::cout<<"Error with file : "<<title<<"\n"; } break; } case 1: { FILE *out = fopen(title.c_str(), "w"); if

Ofstream creates but wont write to file

天大地大妈咪最大 提交于 2019-12-31 07:34:06
问题 I have wrote some code that does a basic fizzbuzz program to test my logging class, for some reason the data is dumped to the console fine and the file is created fine however the log file is empty whenever I open it. My main is here: int main() { logger* loggerObj = logger::createLogger("log.txt"); for (int i = 1; i <= 100; i++) { loggerObj->createLogEvent(i); if (i == 15) { loggerObj->writeLog(); } } and this is my class: int logger::m_instanceCount = 0; logger* logger::loggerObj = new

C++ ofstream not writing to output file?

余生长醉 提交于 2019-12-25 17:18:12
问题 The code is supposed to count the number of a, b, c, d, e, and f characters in the input text file and print the output into a second text file. When I run the code, it creates the output file but doesn't write anything into it. #include<iostream> #include<fstream> #include<cmath> using namespace std; int main(){ // establish counters for the number of each character char x; int acount=0; int bcount=0; int ccount=0; int dcount=0; int ecount=0; int fcount=0; ifstream iFile("plato.txt"); /

C++ ofstream not writing to output file?

≡放荡痞女 提交于 2019-12-25 17:17:08
问题 The code is supposed to count the number of a, b, c, d, e, and f characters in the input text file and print the output into a second text file. When I run the code, it creates the output file but doesn't write anything into it. #include<iostream> #include<fstream> #include<cmath> using namespace std; int main(){ // establish counters for the number of each character char x; int acount=0; int bcount=0; int ccount=0; int dcount=0; int ecount=0; int fcount=0; ifstream iFile("plato.txt"); /

ofstream(mode ios::out) wipes existing file blank when system halt

徘徊边缘 提交于 2019-12-25 07:47:55
问题 The usage scenario is industrial (unstable power supply and other buggy programs/hardware). It is required that the program should come back unaffected when power is off (or blue-screen crash). OS is Windows 7 with NTFS. I use boost::property_tree write json to record parameters to human readable text file. boost::property_tree::write_json("logic.txt", pt); It actually wiped the "logic.txt" sometimes, when system halt. I read the boost source file and write_json calls ofstream with default

Pdf resolution scaling for plotting

橙三吉。 提交于 2019-12-25 05:13:24
问题 I am trying to create a pdf file where I draw a graph from a set of points, 2000+ points. The width of the pdf is set to 612. I want to be able to plot all the points in one line. I am currently drawing at a scale of 1 to 1, one point per pixel. How can I scale my drawing so I can draw all 2000+ points. 来源: https://stackoverflow.com/questions/43301673/pdf-resolution-scaling-for-plotting

ofstream shared by mutiple threads - crashes after awhile

孤者浪人 提交于 2019-12-24 03:05:43
问题 this function takes a ofstream as a reference, then builds struct packets and threads off the structs with the ofstream to a trie matching class. A stack is returned with n matches in order of match distance. The ofstream, packet, and stack are then passed by reference to a print function that writes the matches to the same output file - waiting for when the ofstream is not in use. The problem is the ofstream crashes after half the matches are written. The ofstream, packet, and outfile header

Writing a lot of txt files (90), 5MB per file, takes up to 1400s

佐手、 提交于 2019-12-23 10:28:29
问题 I'm a student in Electrical Engineering. As an assigment I need to implement the back projection algorithm used in medical imaging to form in image. To calculate the final image a lot information is calculated and kept in a vector. At a certain desired resolution (256*256 pixels) of the final image, the program crashes as I run out of RAM, so I decided to write this information to 90 text files. I use ofstream to write these file. The time needed to calculate this information and then storing

Issue on writing wstring to a file for hebrew/arabic language

和自甴很熟 提交于 2019-12-22 14:55:52
问题 I want to read hebrew(unicode) using xerces parser. I am able to read the value in XMLCh. However, while writing it to another file I get gargabe value. I tried using ofstream, wofstream but didnot helped. Let me know your suggestions 回答1: The problem with wofstream is that it accepts the wide string for the open() method but does not actually write wide characters to the file. You have to be explicit about that and imbue() it with a locale that has a codecvt with the encoding you want.

fstream ifstream I don't understand how to load a data file into my program

℡╲_俬逩灬. 提交于 2019-12-22 08:32:55
问题 My professor is very smart but expects complete noobs like me to just know how to program c++. I don't understand how the fstream function works. I will have a data file with three columns of data. I will have to determine with a logarithm whether each line of data represents a circle, rectangle or triangle - that part is easy. The part I don't understand is how the fstream function works. I think I: #include < fstream > then I should declare my file object? ifstream Holes; then I open it: