fstream

std::fstream will not open current process's file, but open() will?

I am attempting to open the current process's executable file for read-write operations (I have additional data attached to the executable), however std::fstream will not open the file in ios::in | ios::out | ios::binary mode, even though open() will (with O_RDWR flag set). Does anyone know why std::fstream will not open the file, while...

win32 c++ fstream wide argument

See link for what I'm talking about. I want to use point 1 in the link and #define tfopen _wfopen #define _T(s) L##s to do exactly what the link says is possible: std::ifstream file( tfopen("filename.txt", _T("r") ); But gcc (mingw) 4.4 says there's no matching call... Am I doing it wrong or is the info in the link above incorre...

[C++] getline returning empty string

I'm having problems with the getline instruction from fstream. this is a snippet from my code: boolean_1=true; while(true) { if(boolean_1) { //some stuff } else { save_file.open("save.txt", fstream::in); //some stuff save_file.close(); } mission_file.open(filename, fstream::in); ...

how can I read exactly 128 bytes from an fstream into a string object?

How do I read exactly 128 bytes from an fstream into a string object? I wrote some code to read the first 128 bytes of a file and print it and then the last 128 bytes of the file and print that. The last part works, since you can easily iterate to EOF, but how do I get exactly 128 bytes from the front? The code below doesn't work since ...

unrecognized type in a function call

I am trying to print into a file in C++ and for some reason I keep getting this weird error: error C2061: syntax error : identifier 'ofstream' I included the following: #include <fstream> #include <iostream> This is my function: void Date::PrintDate(ofstream& resultFile) const { resultFile << m_day << "/" << m_month << "/...

Printing char pointer in C - I keep getting bad formatting

I am reading a line from a file containing the names of people, first line contains names of males, and seconds line contains names of females. Then I want to store these names in two arrays, one for males, one for females, however when I print them I get weird things. I'm not sure if I am not reading them correctly, or printing them inc...

Very basic C++ error

Hey guys, I'm writing the simplest thing ever, just creating an ifstream to read in a text file and I have a weird error. Here is the code (note : the '<' missing for iostream and fstream are well written in my code but I couldn't write them here) #include "genlib.h" #include "simpio.h" #include "random.h" #include "vector.h" #include "...

Storing NULL characters (ASCII 0)

I've created a program in C++ that prompts the user for a filename and for the requested filesize. The program checks if the requested filesize is bigger than the actual filesize and then adds null characters (the ones with code 0) at the end of the file, until the requested filesize is reached. I have done it like this (with fstream): ...

C++ detect space in text file

How can I go about detecting a space OR another specific character/symbol in one line of a file using the fstream library? For example, the text file would look like this: Dog Rover Cat Whiskers Pig Snort I need the first word to go into one variable, and the second word to go into another separate variable. This should happen for ev...

fstream to const char *

What I want to do is read a file called "test.txt", and then have the contents of the file be a type const char *. How would one do this? ...

c++ fstream concurrent access

What will happen if files are accessed concurrently from different processes/threads? I understand there is no standard way of locking a file, only os specific functions. In my case files will be read often and written seldom. Now if A open a file for reading (ifstream) and starts reading chunks. And B opens the same file for writing (o...

Copy data from fstream to stringstream with no buffer?

Is there anyway I can transfer data from an fstream (a file) to a stringstream (a stream in the memory)? Currently, I'm using a buffer, but this requires double the memory, because you need to copy the data to a buffer, then copy the buffer to the stringstream, and until you delete the buffer, the data is duplicated in the memory. std:...