Re: File Input - bad alloc
you already know where it fails. Look at the variable "size": what's its value? Is it too big for a new() to succeed or possibly negative because your file does not exist?
Re: File Input - bad alloc
The debugger (dgb) provides a non-sensical message when I ask it to "print size", which is strange because "size" is apparently basically an integer type:
print size
$2 = {_M_off = -1, _M_state = {__count = 0, __value = {__wch = 0, __wchb = "\000\000\000"}}}
The file definitely exists in the directory, and "size" itself was determined by putting the get pointer at the end of the file. The file is roughly 1.3 Mb in size. In any case, this method worked very well before I altered the way of telling the program the filename. Apparently, for this flexibility with filenames, you need to provide readfile.open with a c-style string.
Re: File Input - bad alloc
not sure what
Code:
string filename;
stringstream(filename) << "bqcd.567.00000.00.1.1.10.0.prop";
does (is it creating a temporary object which is gone after you step over the second line?), but why not just do
Code:
string filename("bqcd.567.00000.00.1.1.10.0.prop");
You can still modify the string. And that size thing does not look good to me.
BTW: do you notice the code tags in this post ;-) ?
Re: File Input - bad alloc
I can't determine what these two lines are doing:
Code:
string filename;
stringstream(filename) << "bqcd.567.00000.00.1.1.10.0.prop"; // Filename, potentially modifiable //
Maybe you want something like:
Code:
stringstream ss;
ss << "bqcd.567.00000.00.1.1.10.0.prop"; // Filename, potentially modifiable //
string filename = ss.str();
Also, I don't know why you need a stringstream at all in this case.
Re: File Input - bad alloc
ifstream:: pos_type is no basic integer type, but it seems it´s implicitely convertible to an integer type.
As Richard already pointed out something seems to go wrong when opening the file because the m_off member is set to -1, which indicates an invalid file position.
Re: File Input - bad alloc
Your suggestion is actually the original form of my program - providing the string explicitly. I can certainly change the name of the file each time I edit the source code, but my goal is to be able to loop through certain variables (mainly integers) which form part of the file name itself. I wish to read multiple files using such a loop, and that data is to be read into the a (larger) multidimensional array.
I've assumed here that I need to use the stringstream class if I want to include variables in the file name. The different numbers in the file name I've used actually correspond to different integers I need to loop over.
Sorry about the missing code tags, it seems I can't edit posts according to the permissions I have.
Re: File Input - bad alloc
Quote:
Originally Posted by
Philip Nicoletti
I can't determine what these two lines are doing:
Code:
stringstream ss;
ss << "bqcd.567.00000.00.1.1.10.0.prop"; // Filename, potentially modifiable //
string filename = ss.str();
Also, I don't know why you need a stringstream at all in this case.
I'll try this suggestion; it seems like a neater way of doing. Although I do need to use the stringstream so that I can loop over multiple files in a future version of the program.