| | |
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:
Solved Threads: 0
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
C++ Syntax (Toggle Plain Text)
#include "stdafx.h" #include <iostream> #include <string> #include <fstream> #include <sstream> #include <stdio.h> #include <stdlib.h> using namespace std; void Fuse_cortex_header_r(){ char str[99999]; string str2, str3, str4; size_t pos, pos1; fstream file_op("c:\\Fuse_cortex.h",ios::in); file_op.getline(str,99999,'@'); string s = str; for(int ctr = 1; ctr < 41; ctr++) { stringstream sstrm, sstrm2, sstrm3; sstrm << "c:\\Fuse_cortex#" << ctr << ".txt"; sstrm2 << "//cls#" << ctr; sstrm3 << "//cls*" << ctr; string filename = sstrm.str(); string start = sstrm2.str(); string end = sstrm3.str(); pos = s.find(start); str2 = s.substr (pos); pos1=str2.find(end); str4 = str2.substr(0,pos1+8); fstream file_op2(filename.c_str(), ios::out); file_op2<<str4; file_op2.close(); } file_op.close(); } void Fuse_cortex_header_w(){ stringstream sstrm; char str[9999]; for(int ctr = 1; ctr < 41; ctr++){ sstrm << "c:\\Fuse_cortex#" << ctr << ".txt"; string filename = sstrm.str(); fstream file_op3(filename.c_str(), ios::in); file_op3.getline(str,9999,'@'); string s_class = str; fstream file_op4("c:\\Fuse_cortex_header.txt", ios::app); file_op4 << s_class; file_op3.close(); file_op4.close(); } } int main () { Fuse_cortex_header_r(); cout << "Successfully Splitted "<< endl; Fuse_cortex_header_w(); cout << "Successfully Combined " << endl; getchar(); return 0; }
Last edited by all blacks; Jul 3rd, 2008 at 11:54 pm.
![]() |
Similar Threads
- Winsock Multi-Client Servers (C++)
- opening and writing to multiple files? (C++)
- Very new to VB.Net, please help (VB.NET)
- How to open multiple textfile (Visual Basic 4 / 5 / 6)
- Implementing a unix shell running commands (Java)
- Movie database Help (C++)
- ASP emails (ASP)
- noobie asking for assistance with file parsing... (Perl)
- I've got Trojan.Holax... is this bad? (Viruses, Spyware and other Nasties)
- not-a-virusadware (Viruses, Spyware and other Nasties)
Other Threads in the C++ Forum
- Previous Thread: Converting a Python Programme to C++
- Next Thread: from file to file
| Thread Tools | Search this Thread |
api array arrays based beginner binary bitmap c++ c/c++ calculator char char* class classes code coding compile compiler console conversion convert count data database delete deploy developer dll download dynamiccharacterarray email encryption error file forms fstream function functions game generator getline givemetehcodez graph gui homeworkhelp homeworkhelper iamthwee ifstream input int java lib list loop looping loops map math matrix memory multiple news node number numbertoword output parameter pointer problem program programming project proxy python random read recursion recursive reference rpg sorting string strings temperature template text text-file tree url variable vector video visual visualstudio win32 windows winsock word wordfrequency wxwidgets





