1,015 questions
- Bountied 0
- Unanswered
- Frequent
- Score
- Trending
- Week
- Month
- Unanswered (my tags)
1
vote
1
answer
53
views
std::ofstream assignment operator -- segfault only occurs in gdb
I am writing a multithreaded program in which each thread opens its own text file for primitive debug logging. Each thread is represented by a separate instance of a class, which manages both the std::...
0
votes
0
answers
72
views
How to trace the curve of max points given sets of points
I was working with Runge Kutta 4 and a quadratic friction. I was running some tests to see for which angle I would have the max range (it's Pi/4 as it would be for no friction). Anyway I got this ...
2
votes
1
answer
194
views
Why are log lines missing without a flush?
I have a simple class in C++20 that logs data to a file line by line for Windows platform. To ensure thread safety, I use a static std::mutex to serialize the write operations.
However, I encounter an ...
2
votes
1
answer
120
views
How to write a large vector to a file correctly?
I want to save a calculated vector of data to a file so I can load it later, avoiding the need to recalculate it every time the program starts.
The issue is that this works fine with relatively small ...
1
vote
1
answer
85
views
Ofstream-based class overwrites files
I have created a "File" class for a C++ project of mine, and its based on ofstream. Here is the simplified code:
file.h
#include <fstream>
#include <mutex>
#include <...
2
votes
0
answers
105
views
ofstream causing memory increase
This is a mini test. The memory used by this C++ program increases from 1KB to 10MB while writing a string to a file. It seems that ofstream didn't release its memory after append.
In theory, std::...
0
votes
1
answer
112
views
About writing/reading "\r\n" to/from a file
Why, if you write a string containing "\r\n" to a file opened in binary mode, and then read that string from the same file, but opened in text mode, then the string will contain '\n' ...
0
votes
1
answer
81
views
Using ifstream/ofstream with Visual Studio. ofstream only outputs last entered password instead of password for specific account
I am learning C++, and have been for about 3 weeks now. Right now, I am writing a program based off of a tutorial (don't worry, I know about tutorial hell. I learned the data types and functions one ...
0
votes
1
answer
138
views
std::ofstream open sucess,but when i call write got a error "no such file or directory" [closed]
I have cpp code like this:
std::ofstream fs;
queue msg_queue;
uint64_t write_size_in_shared_memery =0;
string file_name = "1";
while(true)
{
buffer,buffer_size = msg_queue.pop();
if(!...
1
vote
0
answers
74
views
Is it possible for a specific unit / desktop to be unable to execute ofstream?
So I am a second year computer science student and tinkering with a personal project as a practice before our school activity. I am trying to be familiar with the fstream header. Now, I (or my ...
0
votes
1
answer
108
views
Why the following code works, but if I add "fin.exceptions(ifstream::badbit | ifstream::failbit);" to make the second try/catch work, I get an error?
My code:
int main() {
string path = "D:\\myFile.txt";
Point pointOfIllusion(1, 2, 3);
Point pointOfDesilusion(3, 2, 1);
ofstream fout;
fout.exceptions(ofstream::...
0
votes
1
answer
532
views
Writing Text Data To File using ofstream from a function
I am beginner in c++. trying to store data from one function to another and I have several classes and functions which are inheretance. Would appreciate if someone can explain to me how to use the ...
3
votes
1
answer
203
views
Disappearing content c++ writing to file
Whenever I write the data into the file after rerunning the code the contents of the file disappears
#include <iostream>
#include <fstream>
using namespace std;
int main(){
string ...
-3
votes
1
answer
128
views
std::ofstream opens when debugging in debug configuration, but not when in release configuration (Visual Studio 2022)
Sorry for any poor formatting - this is my first time asking a question here.
I'm working on a project which involves writing some information to a file. When I run or debug the program in debug ...
0
votes
0
answers
43
views
Issue with ofstream class instance not compiling
I'm encountering an issue with writing to a file using ofstream within a C++ class. I've created a minimal example to illustrate the problem:
#include <iostream>
#include <fstream>
class ...