ofstream Questions

5

Solved

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)...
Unglue asked 24/10, 2011 at 14:53

6

I wish I could just print contents of a set/vector/map by using cout << . It doesn't seem so difficult for the stl designers to implement : Assuming that << is defined for T, << f...
Bicorn asked 16/2, 2012 at 22:6

3

Solved

In C++ file handling, I came across ifstream, ofstream and fstream. Can anyone tell me the main difference between these?
Carnay asked 21/5, 2021 at 5:10

3

Deliberately I'm having this method which writes into a file, so I tried to handle the exception of the possiblity that I'm writing into a closed file: void printMe(ofstream& file) { try { ...
Epithelium asked 26/4, 2012 at 16:53

3

Solved

I am writing an MFC program that has a dialog with an "Export" button that will take all of the data that has been entered into the file and export it to a .txt (at some point I want to change this...
Vladi asked 4/5, 2016 at 17:23

3

Solved

I think this should be quite simple, but my googling didn't help so far... I need to write to an existing file in C++, but not necessarily at the end of the file. I know that when I just want to a...
Ryurik asked 4/6, 2015 at 11:37

2

Solved

I'm upgrading existing old code to use VS 2019*, in the code I have the following function that fails on the return line: int foo(const char *fn) const { ofstream out(fn,ios::binary); if (out) ...
Simultaneous asked 9/1, 2020 at 10:5

3

Solved

I have to open some file for writing, and its name contains the tilde sign (~). The following code fails to create the desired text file. If I replace the ~ with /home/oren then everything wo...
Se asked 9/9, 2019 at 10:49

1

Solved

According to this C++ reference: http://www.cplusplus.com/reference/fstream/ofstream/ofstream/, the default open mode for std::ofstream is ios_base::out and it mentions no implict other modes...
Palter asked 17/7, 2019 at 6:41

2

Solved

My code has an ostream object that is accumulated by various modules and ultimately displayed to the console. I'd like ALSO to write this ostreamobject to a file, but do I have to rewrite all of th...
Brent asked 18/3, 2013 at 20:51

8

Solved

The contents of file.txt are: 5 3 6 4 7 1 10 5 11 6 12 3 12 4 Where 5 3 is a coordinate pair. How do I process this data line by line in C++? I am able to get the first line, but how do I get the ...
Poppied asked 23/10, 2011 at 20:24

4

Solved

Here's probably a very noobish question for you: How (if at all possible) can I return an ifstream from a function? Basically, I need to obtain the filename of a database from the user, and if the...
Devanagari asked 8/3, 2010 at 4:58

2

Solved

I have a class that has a filestream of type ofstream. The constructor opens the file in append mode and all the messages always get written at the end of the file. I need to write into outputFile...
Parmenides asked 17/1, 2019 at 13:47

4

Solved

I'm currently using std::ofstream as follows: std::ofstream outFile; outFile.open(output_file); Then I attempt to pass a std::stringstream object to outFile as follows: GetHolesResults(..., std...
Polemic asked 27/11, 2008 at 21:56

1

Solved

I am using C++ 11 to copy a file this way: std::ifstream src(srcPath, std::ios::binary); std::ofstream dst(destinationPath, std::ios::binary); dst << src.rdbuf(); I am creating a new file ...
Afrikaner asked 24/7, 2018 at 6:59

6

Solved

I am implementing file saving functionality within a Qt application using C++. I am looking for a way to check to see if the selected file already exists before writing to it, so that I can prompt...
Hyonhyoscine asked 30/11, 2010 at 17:11

1

Solved

ifstream and ofstream is for input and output in file, and fstream can do task of both them but not inherited from either of ifstream and ofstream, is this code repetition or something else?
Jacinto asked 12/6, 2018 at 12:55

3

Solved

I have the following code: ofstream mOutFile.open(logPath, ios_base::app); string lBuilder; lBuilder.append("========================================================\n"); lBuilder.append("Dat...
Perfoliate asked 9/3, 2012 at 21:9

5

Solved

I have the following code, running on Suse 10.1 / G++ 4.1.0, and it doesn't write to the file: #include <fstream> #include <iostream> int main(){ std::ofstream file("file.out"); fil...
Tiedeman asked 24/6, 2010 at 19:22

2

Trying to read into a file the word, "beef" Later going and editing the contents of the file to whatever to user wants which will be stored in the string, "line" The file never displays and when I...
Seeger asked 29/3, 2018 at 19:20

1

Solved

I'm taking a quiz on an intro level class in C++ and I'm trying to understand a question. After searching the internet and not getting an answer, so here I am. Which of the following function decl...
Maestro asked 11/10, 2017 at 14:3

1

Solved

This is how my Save As works - it is copying the current file's lines until it reaches the first figure and then I use my print methods to print the figure's info and then close the tag. std::ofst...
Cocoa asked 3/5, 2017 at 17:22

3

Solved

I am trying to write PPM file on disk. PPM is a simple image format that consists of ASCII image header and byte array of pixels: P6\n width height\n 255\n [width*height*3 bytes total] This is m...
Loden asked 18/4, 2017 at 19:59

2

Solved

In an answer there was the following code: if (std::ifstream input("input_file.txt")) ; Which seems convenient, limiting the scope of the 'input' variable to where it's confirmed to be valid, h...
Dekeles asked 4/4, 2017 at 19:0

2

Solved

Given the following code: std::ofstream stream("somefile"); if (!stream) { return 1; } When invoking .write(....) and using stdc++ and libc++ the stream is in binary mode (std::ios::binary). ...
Jerkwater asked 23/2, 2017 at 10:15

© 2022 - 2025 — McMap. All rights reserved.