| | |
how to read many text file?
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
U use ifstream and ofstream that is to read u use ifstream and to write u use ofstream..... assuming that u have declared the ofstream and ifstream files but to make a long story short....
U have to declare ur ifstream and ofstream files.... u can achieve that by doing the ff
U have to declare ur ifstream and ofstream files.... u can achieve that by doing the ff
ifstream in_file; and ofstream out_file; and then U need to open them that is reading and writting using in_file.open("eyam.txt"); and out_file.open("eyam.txt"); u use ifstream variable to read and ofstream's to write so U will have something like out_file << number; whatever u wana write and use in_file to read whatever u wana read Some people get so rich they lose all respect for humanity. That's how rich I want to be.
•
•
Join Date: Apr 2007
Posts: 14
Reputation:
Solved Threads: 1
•
•
•
•
I have this to file.First
ayam.txt
10 20 30 60 90 50 40
and itik.txt
a b c d e f g h i
How to call read and write the ayam.txt and itik.txt into one file.
which first i would like to cout the ayam.txt and then itik.txt.
#include <iostream.h>
#include <string.h>
#include <fstream.h>
ofstream output_file("out.4", ios::app);
class MERGE_FILE{
public: // public interfaces for this class
MERGE_FILE(char *, int);
MERGE_FILE operator + (MERGE_FILE &);
private: // private var to be used by this class only
char inputs[20][10]; // char array to hold file inputs
char in_file[10]; // array to hold input file name
}; //END OF CLASS INTERFACE
MERGE_FILE::MERGE_FILE(char * i_f, int x)
{
ifstream input_file(in_file, ios::in);
int i;
if (strcmp(i_f, "empty")==0)
{
strcpy(in_file,"No input file");
}
else if (strcmp(i_f, "empty")!=0)
{
n=x; //number of inputs to read
strcpy(in_file,i_f);
for (i=0;i<n;i++)
{
input_file>> inputs[i];
}
output_file<<"INPUT FILE NAME IS "<<i_f<<"."<<endl;
output_file<<"Read "<<n<<" inputs "<<endl;
}
else {}
}
MERGE_FILE
MERGE_FILE::operator + (MERGE_FILE & other_obj)
{
int i;
MERGE_FILE temp_obj("empty",0);
temp_obj.n =n + other_obj;
for (i=0; i<n; i++)
{
temp_obj.intputs= inputs[i];
}
for(i=0;i<other_obj.n;i++)
{
temp_obj.inputs[i+n]=other_obj.inputs[i];
}
output_file<<" Theres "<< n<< " inputs in first file"<<endl;
output_file<<" Theres "<<other_obj.n<< " inputs in second file"<<endl;
output_file<<" Total inputs equal "<<temp_obj.n<<endl;
return temp_obj;
} Last edited by scarface3288; Apr 1st, 2008 at 11:40 am.
![]() |
Similar Threads
- Read text file to a certain point (C#)
- Read text file through console application (VB.NET)
- How do I read a text file into a 2D vector? (C++)
- read text file (C)
- read text file (C#)
- using a "for" loop to read a text file (VB.NET)
- Text File Input and manipulation (C++)
Other Threads in the C++ Forum
- Previous Thread: array of strings
- Next Thread: Help with C++ PLEASE
| Thread Tools | Search this Thread |
api array beginner binary bitmap c++ c/c++ calculator char char* class classes coding compile compiler console conversion count data database delete desktop developer directshow dll download dynamic email encryption error file forms fstream function functions game getline google graph gui homeworkhelper iamthwee ifstream input int integer java lib linkedlist linker linux 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 return rpg sorting string strings struct template templates test text text-file tree unix url vector video visualstudio win32 windows winsock word wordfrequency wxwidgets





