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)...
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...
3
Solved
In C++ file handling, I came across ifstream, ofstream and fstream. Can anyone tell me the main difference between these?
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
{
...
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...
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...
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...
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...
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 ...
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...
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...
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 ...
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...
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?
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...
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...
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...
1
Solved
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...
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
1 Next >
© 2022 - 2025 — McMap. All rights reserved.