file handling

how do i open and read a .txt file which is displayed in another .txt file using c++ ?
You have to open the first file, read the name of the second file, then open it.
A.txt contains B.txt name

So...

Open file A

read File A

close file A

Open file B with the info obtained in File A

http://www.cplusplus.com/doc/tutorial/files/

http://www.cplusplus.com/reference/clibrary/cstdio/FILE/
thank you for your help .but i wanted to know what if there were "n" file names in the textfile A.txt
i mean what if

A.txt contains B.txt ,C.txt , D.txt name

so how to i access B,C,D ..and also these filenames B,C,D are unknown to me..

please help ...thank you
1
2
3
4
5
6
7
8
9
10
11
12
13
ofstream myfile;
myfile.open ("example.bin", ios::out | ios::app | ios::binary); 

if (myfile.is_open())
  {
    while ( myfile.good() )
    {
      getline (myfile,line);
      ofstream* pFile = new ofstream();
      pFile->open(line,....);
    }
    myfile.close();
}


http://www.cplusplus.com/doc/tutorial/files/

Just read that articel and you will find everything you need.
and next time, try to include some code and some guidelines to what you are trygin to do!
it´s a ton easyer that way rather than reading "please, help!"

Cheers
yes sure il do that.thank you soo much for your help..
i have a cobol program and there are around 3 functions in it..and these functions will have inner functions also..
i need to create a c++ program to list out these main functions and also the inner functions into a textfile..how do i do dat?

this is my sample cobol program


$ SET SOURCEFORMAT"FREE"
IDENTIFICATION DIVISION.
PROGRAM-ID. DriverProg.
AUTHOR. Michael Coughlan.

ENVIRONMENT DIVISION.
DATA DIVISION.

WORKING-STORAGE SECTION.
01 UserNumber PIC 99.

01 PrnResult PIC 9(6).

01 Parameters.
02 Number1 PIC 9(3).
02 Number2 PIC 9(3).
02 FirstString PIC X(19) VALUE "First parameter = ".
02 SecondString PIC X(19) VALUE "Second parameter = ".
02 Result PIC 9(6) COMP.

PROCEDURE DIVISION.
Begin.
PERFORM Call MultiplyNums// these are the main functions displayed in a textfile

PERFORM Call Fickle//"
PERFORM Call Steadfast//"

PERFORM MakeFickleSteadfast.

STOP RUN.


Inside these functions i have a set of other functions ..All three of them MultiplyNums,Fickle,Steadfast are placed in a separate textfile.

i have created a code to access the main functions

#include<iostream>
#include<fstream>
#include<string>


using namespace std;

int main ()
{

char* search = "Call "; // search pattern;
string search1=".txt";
string sample;

int offset;

string line;
string line2;

string line1;
char func[100];
string str1;

size_t pos;

int n;
ofstream outfile;
outfile.open("filename.txt",ios::in);
ifstream Myfile;
Myfile.open ("s1.txt",ios::out);

if(Myfile.is_open())
{
while(!Myfile.eof())
{
getline(Myfile,line);
if ((offset = line.find(search, 0)) != string::npos)
{
pos = line.find("Call ");
str1 = line.substr(pos+5);
sample=str1 + search1;
outfile<<sample<< endl;
}
}
Myfile.close();
}
else
cout<<"Unable to open this file."<<endl;

system("pause");
return 0;
}


and the output i get is

MultiplyNums.txt
Fickle.txt
Steadfast.txt

which i have placed in a textfile called filename.txt..

now i want to open these 3 textfiles which is inside filename.txt and perform the same operation to display the function names inside these..

how do i do dat ?
And the cobol program above is placed inside s1.txt
somebdy please help..
1. Code Tags?
2. I don't know of anything called Cobol...
i have a cobol program and there are around 3 functions in it..and these functions will have inner functions
C and C++ do not support inner functions (local functions). But there are various ways to simulate the effect. In the end, it's just controlling scope, so as long as the signatures don't clash, just declare then at global scope like everything else.

i need to create a c++ program to list out these main functions and also the inner functions into a textfile..how do i do dat?
That's a little bit tricky. You're now in the business of parsing a COBOL program. Do you know anything about parsing?
Topic archived. No new replies allowed.