Read from multiple file and Write into 1 file using loop

Please support our C++ advertiser: Intel Parallel Studio Home
Thread Solved

Join Date: Jul 2008
Posts: 9
Reputation: all blacks is an unknown quantity at this point 
Solved Threads: 0
all blacks all blacks is offline Offline
Newbie Poster

Read from multiple file and Write into 1 file using loop

 
0
  #1
Jul 3rd, 2008
I wan to read from multiple files and write into 1 file....the fuse_cortex_header_r function will read a file and then break the file into several file which only consist of classes...for fuse_cortex_header_w file, i would like to read all the files which have been writen by previous function and write everthing back into 1 file....it basically works as a splitter and combiner...But the write function doesnt seems working very well, i only could read 1 file and write it in 1 file, there is still 39 classes to be read and written after the 1st file..here is the code
  1.  
  2. #include "stdafx.h"
  3. #include <iostream>
  4. #include <string>
  5. #include <fstream>
  6. #include <sstream>
  7. #include <stdio.h>
  8. #include <stdlib.h>
  9.  
  10.  
  11. using namespace std;
  12.  
  13.  
  14. void Fuse_cortex_header_r(){
  15.  
  16. char str[99999];
  17. string str2, str3, str4;
  18. size_t pos, pos1;
  19. fstream file_op("c:\\Fuse_cortex.h",ios::in);
  20. file_op.getline(str,99999,'@');
  21.  
  22. string s = str;
  23.  
  24. for(int ctr = 1; ctr < 41; ctr++)
  25. {
  26.  
  27. stringstream sstrm, sstrm2, sstrm3;
  28. sstrm << "c:\\Fuse_cortex#" << ctr << ".txt";
  29. sstrm2 << "//cls#" << ctr;
  30. sstrm3 << "//cls*" << ctr;
  31. string filename = sstrm.str();
  32. string start = sstrm2.str();
  33. string end = sstrm3.str();
  34. pos = s.find(start);
  35. str2 = s.substr (pos);
  36. pos1=str2.find(end);
  37. str4 = str2.substr(0,pos1+8);
  38. fstream file_op2(filename.c_str(), ios::out);
  39. file_op2<<str4;
  40. file_op2.close();
  41.  
  42. }
  43. file_op.close();
  44. }
  45.  
  46.  
  47. void Fuse_cortex_header_w(){
  48.  
  49. stringstream sstrm;
  50. char str[9999];
  51.  
  52. for(int ctr = 1; ctr < 41; ctr++){
  53.  
  54.  
  55. sstrm << "c:\\Fuse_cortex#" << ctr << ".txt";
  56. string filename = sstrm.str();
  57.  
  58. fstream file_op3(filename.c_str(), ios::in);
  59. file_op3.getline(str,9999,'@');
  60.  
  61. string s_class = str;
  62.  
  63. fstream file_op4("c:\\Fuse_cortex_header.txt", ios::app);
  64. file_op4 << s_class;
  65.  
  66. file_op3.close();
  67. file_op4.close();
  68.  
  69. }
  70.  
  71. }
  72. int main ()
  73. {
  74. Fuse_cortex_header_r();
  75. cout << "Successfully Splitted "<< endl;
  76. Fuse_cortex_header_w();
  77. cout << "Successfully Combined " << endl;
  78. getchar();
  79. return 0;
  80. }
Last edited by all blacks; Jul 3rd, 2008 at 11:54 pm.
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC