Skip to main content
Filter by
Sorted by
Tagged with
3 votes
1 answer
147 views

The spec says the following for creating an object using an existing storage - [intro.object#3]: If a complete object is created ([expr.new]) in storage associated with another object e of type “...
Amir Kirsh's user avatar
  • 14.5k
0 votes
0 answers
44 views

What is the difference between using this form of code fstream file{"foo.txt", ios::out}; and fstream foo{"foo.txt", fstream::out}; and this fstream file{"foo.txt", file....
A.H's user avatar
  • 29
4 votes
3 answers
152 views

I'm writing a function in C++ that has to return more than one value, and I know that I can't. So I thought to pass the function two pointers to the files I want to open. This is the code and then I'...
Alessio Spinellino's user avatar
1 vote
0 answers
111 views

I want to coordinate access to a shared text file between two processes, specifically: a writer that seldom updates the file; a reader that frequently read the file. I want a solution implemented ...
manlio's user avatar
  • 19.2k
2 votes
3 answers
289 views

I need to read many different files in succession as fast as possible. It's not one big file, but many small ones. The files I try to read from are the stat files in /proc/<pid>/stat I am using ...
Plat00n's user avatar
  • 317
-1 votes
1 answer
119 views

I am running this through Visual Studio 2022 and using IrfanView 64 as the ppm viewer. This code is refusing to output to a file of any sort (a txt or ppm is the goal here). The goal of the code is to ...
HopefulWit's user avatar
1 vote
0 answers
124 views

Code does not create .txt files to output Updated: this code is working on friend's PC, but on on my PC. We both installed same mingw file. Both have Windows 11, both tried on VS code and Far Manager ...
HMS Tree's user avatar
7 votes
1 answer
165 views

I am tring to compile some code wrote for the msvc compiler with msys2 gcc (msys2-msys2 not msys2-mingw) and it contains wstring filename; ifstream file(filename); I tried to find a way to use ...
Stas Badzi's user avatar
2 votes
1 answer
109 views

When using <fstream> with g++ -D_GLIBCXX_HAVE__WFOPEN=1 -D_GLIBCXX_USE_WCHAR_T=1 (msys2 gcc 13.3.0) it throws an error /usr/lib/gcc/x86_64-pc-msys/13.3.0/../../../../x86_64-pc-msys/bin/ld: /tmp/...
Stas Badzi's user avatar
1 vote
1 answer
103 views

#include <iostream> #include <fstream> #include <sstream> int main() { std::ifstream file("data.txt"); std::string line, numStr; // read first line std:...
Mathieu's user avatar
  • 332
0 votes
0 answers
59 views

I created logger lib, and its works fine in test projects. But in my .dll project when I use create file method, it throws runtime access violation error in open method fstream.h file. basic_filebuf* ...
f1oating's user avatar
0 votes
0 answers
50 views

I want to find a (fixed length) key in a file and update a value afterward. However, I found a strange behavior where I can't write to the file after reading from it. Here is an example: #include <...
Nejc Jezersek's user avatar
0 votes
2 answers
162 views

I have a C++ program which reads a specific line from a file based on the index of that line. The index is calculated elsewhere in the program. My question is: can I open a file (i.e., a .txt) and ...
Prof.Chewbacca's user avatar
-1 votes
2 answers
126 views

I'm trying to create a system, which allows me to write data to a txt file if it doesn't exist in it. For some reason, it doesn't work with existing data, and I can't seem to understand why. It has no ...
Фёдор Руденко's user avatar
0 votes
1 answer
119 views

Context: This was an exercise for a "course", where I was given a file with ASCII numbers and was told to decode the ASCII numbers into words. Each word was written in one line, with each ...
joler's user avatar
  • 37
0 votes
2 answers
83 views

Why is this code not creating several files? ofstream should create a file when it encounters a file name that doesn't exist. However, for some reason, even though the names are different, it creates ...
Фёдор Руденко's user avatar
-1 votes
1 answer
175 views

I need to read numbers from file, calculate sum and write sum on last line, then read sum back from file. It works okayish up until i need to read last line back from file. Can't get it to work. So, ...
Janiferi's user avatar
1 vote
0 answers
49 views

I am new to Visual Studio and I found out that for Visual Studio to compile the folder you need to create a project folder that creates it inside the user folder, now I used fstream to try to create a ...
huk 30's user avatar
  • 11
0 votes
1 answer
112 views

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' ...
Pavel's user avatar
  • 354
5 votes
1 answer
135 views

Executing the following code #include <iostream> #include <fstream> int main() { std::fstream fs{"/dev/shm/test.bin", std::ios::in | std::ios::out | std::ios::binary | std::...
Trauer's user avatar
  • 2,131
-3 votes
1 answer
74 views

When I click a button, I want a string value entered by a user to be stored in a file. private: System::Void add_task_Click(System::Object^ sender, System::EventArgs^ e) { ofstream ...
user25745846's user avatar
0 votes
0 answers
74 views

I have written a class for handling text files and it looks like this. #include <fstream> #include "String.h" class TextFile { std::fstream stream; public: TextFile(const ...
Marcell's user avatar
  • 255
1 vote
2 answers
214 views

Suppose I have a std::filesystem::path, which I then open as an std::ifstream, and suppose that I want to determine its size (e.g. maybe I want to read the whole file). Should I prefer calling auto ...
einpoklum's user avatar
  • 138k
0 votes
0 answers
49 views

I am working on a maze solving algorithm. I input a text file formatted with 2 numbers at the top defining the width and height. Then a G for goal, S for start, # are walls, . are open spaces. Example ...
Moe98's user avatar
  • 11
-1 votes
3 answers
59 views

I want to make a score system in my game that will save the individual score (int score) of every player (string input) as well as the sum of every player score (scoreTotal). To do that I want to keep ...
srstafion's user avatar
2 votes
2 answers
213 views

I am trying to write a chrono::zoned_seconds object as text to a file and then retrieve it and construct another chrono::zoned_seconds object later. How can this be done in a fairly efficient way? I ...
digito_evo's user avatar
  • 3,735
-1 votes
1 answer
126 views

assuming that the included file uses namespace std and contains the std library facilities . i have written a program to write points on the coordinate plane to some input file stream and then use ...
Abdullah Othman's user avatar
-1 votes
1 answer
124 views

Here is my program: #include <fstream> int main() { std::ofstream fout("data.dat", std::ios::binary); for (int isam=0; isam<500; isam++) fout.write((char*) &isam, 4); ...
Steve Lowe's user avatar
3 votes
1 answer
120 views

I am currently trying to make a simple function that reads a file's contents and stores it into either a std::string or char array. I have run into issues where the data is read completely fine within ...
Henry Boyer's user avatar
0 votes
0 answers
60 views

EDIT: Based on suggestion of Retired Ninja, I serialized the data when writing and reading resulting into another two functions void writeString(std::fstream& file, const std::string& str) { ...
Mihai's user avatar
  • 97
0 votes
1 answer
110 views

Im trying to write a program that will read a file and set a name and the 5 votes the person casts. The problem is that the fstream is not reading the file correctly. However if I open another object ...
Moe98's user avatar
  • 11
0 votes
0 answers
53 views

I am trying to draw a screen of 480 x 270 pixels on the screen, all of them randomly colored, and see how fast I can do this. I was originally trying DirectX, and this worked (which is how I know my ...
Mattematics's user avatar
0 votes
0 answers
67 views

I am trying to read the HEX data of a .bin file to a string. At the start of the string there is a bunch of FFs and after that the actual data starts. I want to only read the data that the .bin file ...
Shmurkio's user avatar
-1 votes
2 answers
713 views

I want to extend the std::fstream class from the <fstream> header. I plan to add a couple functions like std::fsteam create(path), std::vector<std::string> read_lines(path), etc. What Im ...
itsrxmmy's user avatar
0 votes
1 answer
90 views

I want to wrap a new class to generate a file and make some auto resource recycle and some additional operate with the new file. So I make a new class like class TmpFile { private: std::string ...
f1msch's user avatar
  • 665
3 votes
0 answers
174 views

Is there a standard/cross-platform way to throw a descriptive exception with the reason why the file failed to be opened? (Eg: "Read-only directory", "Permission denied", "...
M. Victor's user avatar
0 votes
0 answers
209 views

I was trying to implement a simple text editor and was met with this problem. When using std::wofstream to save buffer to file, I keep a WEOF at the end of the buffer for convenience of other parts in ...
Shadow Stalker's user avatar
-1 votes
1 answer
116 views

so i have a small issue. I am working on a school assignment and i just can't figure out how to get the solution. So the assignment needs me to read a file in binary form and then find certain bit ...
simsam's user avatar
  • 45
3 votes
1 answer
201 views

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 ...
EdwardTheTrain's user avatar
0 votes
0 answers
96 views

I'm writing a brainfuck interpreter in C++. One of its language features is that in a loop if the current byte != 0 then go back to the beginning of the loop until it's == 0. My approach is reading a ...
ahmed's user avatar
  • 98
0 votes
2 answers
130 views

I'm currently learning writing to and reading from a file in C++, and I stumbled across something I'm not sure I understand. I'm writing 5 different integers to "ages.txt" file and then I'm ...
jakarta_tea's user avatar
-1 votes
1 answer
234 views

I think I may not have the file I'm trying to read in the right spot but i've put it everywhere possible in the IDE and it is still not working. Ive even put it next to the .exe for my program and it ...
Christian Galdi's user avatar
0 votes
0 answers
28 views

Given #include<string> #include<stringstream> #include <fstream> int main(int argc, char* args[]) { std::fstream file("MyFile.txt", std::fstream::in); std::stringbuf ...
Raffaello's user avatar
  • 1,705
0 votes
1 answer
163 views

I use std::fstream to read text files line by line with the member function getline(). It uses buffer of limited size, and sometimes lines on input are longer than the buffer. After the first reading ...
Vladlen's user avatar
  • 143
-1 votes
1 answer
70 views

Code outputs, "file not open." union converter_t { char byte[4]; short int word[2]; int dword[1]; } converter; class enhancedfstream: public fstream { public: enhancedfstream(...
reallyhuh's user avatar
0 votes
1 answer
126 views

How can I simultaneously read and write to binary files? I cannot seem to figure out why my program is erroring out and every bit of debugging I can think of does not yield me any good results. The ...
ModernEraCaveman's user avatar
-3 votes
1 answer
97 views

I'm trying to read the information from a .txt file but something very strange is happening. Here's the code: ifstream fichier(dir); fichier.open(dir); if (fichier.is_open()) cout << &...
Diego's user avatar
  • 175
1 vote
0 answers
69 views

I established a port-communication that logs some data from the serial port in an text field. The communication is successful an the text is displayed in the textfield. Next, I would like to write the ...
3xcelsior's user avatar
0 votes
0 answers
38 views

This simple function, in C++17, changes a single character in a text file to a passed in tracking choice (0 or 1). The problem I'm having with this code is that the put statement is changing more than ...
Tim Cerka's user avatar
-1 votes
1 answer
129 views

I made a program that is supposed to be a simple text editor that can create (if not existed) a .cpp file, read the content of the file and display it on the console, and modify the content and save ...
Zerocool_m12's user avatar

1
2 3 4 5
58