• Post Reply Bookmark Topic Watch Topic
  • New Topic

Not able to write complete output to file  RSS feed

 
Ashwin Rao
Ranch Hand
Posts: 89
C++ Java Python
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I'm trying to find out the minimum scalar product of a given two vectors. I've succeeded in my attempt to find out the minimum scalar product. I found the question here. I'm trying to solve the small input. My program calculates the minimum scalar product for all 1000 cases but is only writing 845 of them to the file. I don't understand what's the problem. I think it may have something to do with FileWriter. Any help is much appreciated.
My code is given below:
 
Ashwin Rao
Ranch Hand
Posts: 89
C++ Java Python
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I had forgotten to close the writer!!
After I added writer.close() I got the output! Sorry for the trouble!
 
Liutauras Vilda
Sheriff
Posts: 4917
334
BSD
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

You still can improve your program, by:

1. Avoiding explicit imports on lines 1, 2.
2. By shortening your "main" method to a 1 or 2 lines in total.
3. By decomposing your code to a methods, which takes care of a single tasks.
 
Campbell Ritchie
Marshal
Posts: 56525
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How did you close the writer? Did you read the documentation for close() and did this explain your problem?
 
Ashwin Rao
Ranch Hand
Posts: 89
C++ Java Python
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Closing the writer first flushes it and then closes it. So I guess it would have worked if I had just flushed it.
 
Campbell Ritchie
Marshal
Posts: 56525
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes and no. You would have had the file written had you simply called flush() but failing to close the writer can cause a resource leak.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!