Questions tagged [filestreams]
35 questions
22
votes
4 answers
What happens if I never call `close` on an open file stream?
Below is the code for same case.
#include
#include
using namespace std;
int main () {
ofstream myfile;
myfile.open ("example.txt");
myfile << "Writing this to a file.\n";
//myfile.close();
return 0;
}
What…

David Mnatsakanyan
- 455
- 1
- 4
- 15
6
votes
2 answers
Python: Opening a file without creating a lock
I'm trying to create a script in Python to back up some files. But, these files could be renamed or deleted at any time. I don't want my script to prevent that by locking the file; the file should be able to still be deleted at any time during the…

SilentSteel
- 2,344
- 1
- 28
- 28
4
votes
1 answer
Can a file stream destructor throw an exception in C++?
Can a file stream destructor throw an exception, e.g., if file closing operation fails?
auto f = new std::ofstream("data.txt");
f->exceptions(std::ofstream::failbit | std::ofstream::badbit);
...
delete f; // May throw?
Can I…

Daniel Langr
- 22,196
- 3
- 50
- 93
3
votes
1 answer
Implementing stop and restart in file stream transfer - how to? C# .NET
I'm looking for texts or advice on implementing stop and restart in file stream transfer.
The goal is for the application to use a single read source, and output to multiple write sources, and be able to restart from a recorded position if a…

gbro3n
- 6,729
- 9
- 59
- 100
3
votes
2 answers
C++ File Write includes the memory address of the string instead of the contents
All,
I'm still learning C++ but I have an issue in a project I'm tinkering with that I'm curious about. I've noticed that when I try to print the contents of a string that is a member of a class, I get the memory address instead of the contents. I…

sallou
- 99
- 9
3
votes
1 answer
Node CSV Parser
I'm using the node package 'csv', and I've run into an issue in the most obvious use case for the package and am not sure how to proceed. Package repo: https://github.com/wdavidw/node-csv
I need to,
1: read in a csv file, and perform a single…

Derek
- 722
- 1
- 6
- 16
3
votes
1 answer
How to wait for cpp fstream to finish writing before moving on?
I have a c++ driver that contains a do-while loop. Inside this loop, I have data written to disk every so many iterations by a member function of a class. The funny thing is, the function seems to write almost all of the data for the nth time it…

codeAndStuff
- 507
- 6
- 19
2
votes
1 answer
error: 'invalid operands' to binary operator <<
I'm getting the following error:
invalid operands of types 'char' and unresolved overloaded function type>' to binary 'operator<<'
What does it mean?
#include
#include
using namespace std;
int main()
{
ifstream inFile;
…

user1248923
- 31
- 1
- 1
- 2
2
votes
2 answers
UTF-8-compliant IOstreams
Does GCC's standard library or Boost or any other library implement iostream-compliant versions of ifstream or ofstream that supports conversion between UTF-8-encoded (file-) streams and a std::vector or std::wstring?

Nordlöw
- 11,838
- 10
- 52
- 99
2
votes
2 answers
c++ filestream problems when opening file in read write mode
Consider the following code snippet:
const char * filePath = "C:/blah.mtt";
fstream fs(filePath, ios::in | ios::out | ios::binary);
if (fs.fail())
std::cout << "Failed to open the file!\n";
the fs.fail() check succeeds always. Does it mean that…

Arun
- 3,138
- 4
- 30
- 41
2
votes
0 answers
File metadata is saved in file body in WCF file upload by Stream
I am uploading a file through a WCF service.
[OperationContract(Name = "UploadManual")]
[DataContractFormat]
[WebInvoke(Method = "POST",
UriTemplate = "UploadManual/",
BodyStyle =…

Priyank
- 1,353
- 9
- 13
2
votes
2 answers
c++ reading a a txt file line by line into a char array within an array of structures
I'm new to C++ and having a bit of trouble understanding the whole reading a file stream thing.. any help would be appreciated... here's where i'm having trouble
I Have an array of structures like this; (no I'm not allowed to use string to store…

user3427104
- 23
- 1
- 4
1
vote
2 answers
Java open stream from an arbitrary location in file
I want to get a Stream from some arbitrary position in an existing file, for example I need to read/write from/to a file starting with 101th byte.
Is it safe to use something like that?
final FileInputStream fin = new…

Vic
- 21,473
- 11
- 76
- 97
1
vote
2 answers
Avoiding Error Flags when Reading Files
This is how I usually read files with std::ifstream:
while (InFile.peek() != EOF)
{
char Character = InFile.get();
// Do stuff with Character...
}
This avoids the need of an if statement inside the loop. However, it seems that even peek()…

Maxpm
- 24,113
- 33
- 111
- 170
1
vote
1 answer
Why TFileStream.write produces incorrect data? Dephi 7
I tried to create a function/method which should write to a file with
a header filled with zeros
header := StringOfChar(char(0), 11*offsetSize);
But when I check the file which was created, it has the following values…

John Boe
- 3,501
- 10
- 37
- 71