Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.c++ > #15404 > unrolled thread
| Started by | sharat <aaliya.zarrin@gmail.com> |
|---|---|
| First post | 2012-04-16 04:10 -0700 |
| Last post | 2012-04-16 21:57 +0000 |
| Articles | 2 — 2 participants |
Back to article view | Back to comp.lang.c++
ofstream Error: Failed to write file: Result is too large. sharat <aaliya.zarrin@gmail.com> - 2012-04-16 04:10 -0700
Re: ofstream Error: Failed to write file: Result is too large. jt@toerring.de (Jens Thoms Toerring) - 2012-04-16 21:57 +0000
| From | sharat <aaliya.zarrin@gmail.com> |
|---|---|
| Date | 2012-04-16 04:10 -0700 |
| Subject | ofstream Error: Failed to write file: Result is too large. |
| Message-ID | <6b4b4072-6cd9-4724-a9cf-45ed50e13abd@f5g2000vbt.googlegroups.com> |
Hi ,
I facing problem while writing into file..
For my problem, File path withh be available after some time. So to
avoide "File does not exist " error I am sleeping in a loop for some
time ana again try to open a file. If file open successfully I will
write into file else through an exception.
If flow enters into while loop , and got the file after Sleep for few
seconds then problem is comeing ..
Failed to write to File: Result is too large"
where as if it does not go into while loop then it is able to create
file and write into it...
I am unable to find the reason. Can anybody help please???
Sample code :
int retryLoopCount = 0;
ofstream myfile;
myfile.open ((const char*)filePath);
while(! (myfile.is_open()))
{
Sleep( (retryLoopCount*2+1)*1000);
if(retryLoopCount++ > RETRY_COUNT)
{
int erCode = errno;
err.Format ("Failed to open file '%s' for writing: %s"
, (const char*)filePath
, strerror(erCode)
);
myfile.close();
throw Exception ------ (// throw Exception -- - I have not copied
the exact sample code here)
}
myfile.open ((const char*)filePath);
}// while retry.
myfile<< (const char*)content;
if (myfile.bad() ) {
int erCode = errno;
err.Format ("Failed to write file '%s': %s"
, (const char*)filePath
, strerror(erCode)
);
myfile.close();
throw Exception ----- (// throw Exception here -- I have not copied
the exact sample code here )
}
myfile.close();
[toc] | [next] | [standalone]
| From | jt@toerring.de (Jens Thoms Toerring) |
|---|---|
| Date | 2012-04-16 21:57 +0000 |
| Message-ID | <9v3iv0FmmlU1@mid.uni-berlin.de> |
| In reply to | #15404 |
sharat <aaliya.zarrin@gmail.com> wrote:
> I facing problem while writing into file..
> For my problem, File path withh be available after some time. So to
> avoide "File does not exist " error I am sleeping in a loop for some
> time ana again try to open a file.
Can you please explain why you would have to try repeatedly
to open a file? If it fails something is wrong and waiting
and then retrying usually doesn't help (well, except if there
are permission problems and you manually fix them while the
program is waiting). So I don't understand what this is all
meant to be good for.
> If file open successfully I will
> write into file else through an exception.
> If flow enters into while loop , and got the file after Sleep for few
> seconds then problem is comeing ..
> Failed to write to File: Result is too large"
"Result is too large" smells like an errno of ERANGE, something
which isn't something I would expect from I/O trouble...
> where as if it does not go into while loop then it is able to create
> file and write into it...
> I am unable to find the reason. Can anybody help please???
Drop all that repeatedly trying to open the file (or, please,
give some explanation why you think it's necessary) - some-
thing strange must be going one here if it's needed anyway.
> Sample code :
> int retryLoopCount = 0;
> ofstream myfile;
> myfile.open ((const char*)filePath);
You can make that just
std::ofstream myfile( filePath );
And why the C-style cast? Or is 'filePath' perhaps not a char
array or pointer? Should that be the case (e.g. 'filePath' is
a pointer to a std::string) then the cast will just result in
additional grieve.
> while(! (myfile.is_open()))
> {
> Sleep( (retryLoopCount*2+1)*1000);
> if(retryLoopCount++ > RETRY_COUNT)
> {
> int erCode = errno;
> err.Format ("Failed to open file '%s' for writing: %s"
> , (const char*)filePath
> , strerror(erCode)
> );
> myfile.close();
> throw Exception ------ (// throw Exception -- I have not copied the exact sample code here)
If you want help it's typically better to post your actual code
instead of something you think is at the heart of the problem -
you could be wrong and may have left out the important bits.
> myfile.open ((const char*)filePath);
> }// while retry.
> myfile<< (const char*)content;
Why the C-style cast? The '<<' operator will work fine on a
non-const char array or a pointer to a non-const char array.
Or is 'content' something else?
> if (myfile.bad() ) {
> int erCode = errno;
> err.Format ("Failed to write file '%s': %s"
> , (const char*)filePath
> , strerror(erCode)
> );
> myfile.close();
> throw Exception ----- (// throw Exception here -- I have not
> copied the exact sample code here )
> }
> myfile.close();
Regards, Jens
--
\ Jens Thoms Toerring ___ jt@toerring.de
\__________________________ http://toerring.de
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.c++
csiph-web