ofstream

C++ How to actually use pubsetbuf in ofstream?

妖精的绣舞 提交于 2021-02-08 10:48:44
问题 I have a program that writes a temporary file to be used with gnuplot. The file varies in size and it can get to several hundreds of kB, if not MB. Everytime it's written to disk, strace only shows some 8kB at a time. I would like to avoid unnecessary disk writes by setting a buffer greater than this. One of the answers here, on SO, said that 128kB is about the maximum before it starts behaving badly. I have searched and found out that I can modify the buffer, something like this: int sz

C++ How to actually use pubsetbuf in ofstream?

蹲街弑〆低调 提交于 2021-02-08 10:44:12
问题 I have a program that writes a temporary file to be used with gnuplot. The file varies in size and it can get to several hundreds of kB, if not MB. Everytime it's written to disk, strace only shows some 8kB at a time. I would like to avoid unnecessary disk writes by setting a buffer greater than this. One of the answers here, on SO, said that 128kB is about the maximum before it starts behaving badly. I have searched and found out that I can modify the buffer, something like this: int sz

Why do I make “use of deleted” function when passing a std::ofstream as parameter? [duplicate]

余生颓废 提交于 2021-02-04 17:48:02
问题 This question already has answers here : Why copying stringstream is not allowed? (3 answers) C++ copy a stream object (5 answers) Closed 5 years ago . I have a member that is std::ofstream fBinaryFile and a void setFile( std::ofstream& pBinaryFile ) { fBinaryFile = pBinaryFile; } output: Data.h:86:16: error: use of deleted function ‘std::basic_ofstream<char>& std::basic_ofstream<char>::operator=(const std::basic_ofstream<char>&)’ fBinaryFile = pBinaryFile; ^ I understood that copy in std:

How to read n values from txt file using C++

旧巷老猫 提交于 2021-01-28 21:29:03
问题 I have the following c++ code by which I am reading values from .txt file Could you please help me to improve the code such that I can read not only 14 values but n values from the .txt //reading from text file static std::vector<double> vec; double a[14]; //values got read from txt file int i = 0; void readDATA() { double value; std::ifstream myFile; myFile.open("filename.txt", std::ios::app); if (myFile.is_open()) { std::cout << "File is open." << std::endl; while (myFile >> value) { vec

Writing boost::multiprecision data type to binary file

两盒软妹~` 提交于 2021-01-28 04:02:18
问题 I was using the boost::multiprecision::uint128_t type in order to perform bitwise operations on a 128 bit value. However I am having trouble writing the 128 bit value out to a binary file. Specifically with the need to pad out the value with zeros. As an example if the uint128_t value was 0x123456 then looking at the file in the hex editor I would want the sequence: 56 34 12 00 00 00 00 00 00 00 00 00 00 00 00 00 #include <boost/multiprecision/cpp_int.hpp> #include <fstream> boost:

Writing Integers to a .txt file in c++

浪尽此生 提交于 2021-01-27 14:21:37
问题 I am new to C++ and want to write data(integers) on a .txt file. The data is in three or more columns that can be read later for further usage. I have created successfully a reading project but for the writing one the file is created but it is blank. I have tried code samples from multiple sites but is not helping. I have to write results from three different equations as can be seen from the code. #include<iostream> #include<fstream> using namespace std; int main () { int i, x, y; ofstream

Using ifstream to assign default value if it was not declared in .txt file

谁都会走 提交于 2021-01-05 09:00:10
问题 Could you please help in modifying the following code to add two things: having the ability to assign manual(default) value to a[i] if i was not available in the .txt file (e.g. first line in text file is 0, 0, 40, , 15 the forth element in nothing and in this case I want to assign it manually in the code to be for instance 70). letting the code read not only numbers but also strings (dealing with numbers and strings for example 0,0,8,"turn_right",4 ) struct Number { double value; operator