| | |
file.close
Please support our C++ advertiser: Programming Forums - DaniWeb Sister Site
Thread Solved |
•
•
Join Date: Oct 2009
Posts: 2
Reputation:
Solved Threads: 0
I've written a program like the follow:
the inner loop just works for the first time. from the scond time in outer loop, I can't inter the inner loop. I gusse there migth be a problem with file.close().
C++ Syntax (Toggle Plain Text)
int main () { . . . . ifstream file1; ifstream file2; ofstream simiralities; simiralities.open("P(0)_P(1).txt", ios::app); file1.open("test1.txt", ios::in); while (!file1.eof()) { . . . file2.open("test2.txt", ios::in); while (!file2.eof()) { . . . . } file2.close(); } simiralities<<number; file1.close(); simiralities.close(); return 0; }
the inner loop just works for the first time. from the scond time in outer loop, I can't inter the inner loop. I gusse there migth be a problem with file.close().
•
•
Join Date: Jun 2009
Posts: 21
Reputation:
Solved Threads: 2
C++ Syntax (Toggle Plain Text)
1. int main () 2. { 3. . 4. . 5. . 6. . 7. 8. 9. ifstream file1; 10. ifstream file2; 11. ofstream simiralities; 12. simiralities.open("P(0)_P(1).txt", ios::app); 13. file1.open("test1.txt", ios::in); 14. // A good way to check if a file has been opened- if (! file1) { cout << "error opening file" << endl; return -1; /*Your program isn't opening your files correctly, and will exit here. Have a gander & see what you can come up with*/ } 15. while (!file1.eof()) 16. { 17. . 18. . 19. . 20. 21. 22. file2.open("test2.txt", ios::in); 23. 24. 25. while (!file2.eof()) 26. { 27. 28. . 29. . 30. . 31. . 32. 33. } 34. 35. file2.close(); 36. 37. 38. } 39. 40. simiralities<<number; 41. file1.close(); 42. simiralities.close(); 43. 44. return 0; 45. }
Last edited by lexusdominus; Oct 12th, 2009 at 10:47 am. Reason: forgot code tags, init
![]() |
Similar Threads
- C++: ifstream file pointer not getting reset (C++)
- Structure char field to a disk file (C)
- About;Blank Please Help, Hijack Log File (Viruses, Spyware and other Nasties)
- Error Message Concerning Reading File From A Drive (C++)
- Text File Input and manipulation (C++)
- Store Bluetooth remote address to a text file (C++)
- Hijackthis log file (Viruses, Spyware and other Nasties)
Other Threads in the C++ Forum
- Previous Thread: what is this for?
- Next Thread: EC++ related problem
Views: 247 | Replies: 3
| Thread Tools | Search this Thread |
Tag cloud for C++
6 api application array arrays assignment beginner binary bitmap c++ c/c++ calculator char class classes code coding compile compiler console conversion convert count data database delete developer display dll email encryption error file forms fstream function functions game generator getline givemetehcodez graph homeworkhelper iamthwee ifstream image input int java lazy lib loop looping loops map math matrix memory multidimensional multiple newbie news node number output parameter pointer problem program programming project proxy python random read recursion recursive reference return sort sorting string strings struct template templates text tree url variable vector video visual visualstudio win32 windows winsock word wordfrequency wxwidgets





