|
Hello.
O.S. RHL 8
Compiler gcc ver 3.2
I need to write a program that opens a datafile and then
opens each line (filename).
I can only get the program to open the last line in the file.
Datafile contents
===================
AZ500.txt
AZ600.txt
the program will only open AZ600.txt
Program Segment
int main(){
// vars
char input[20];
char buffer[20];
string line;
string file;
vector<string> Data;
cout << "Input File : ";
cin >> input;
ifstream inputfile(input);
while (inputfile.getline(buffer,20)){ // should remove \n
ifstream datafile(buffer);
Am I not removing a newline char or something? Is this
preventing the first line from opening?
Thanks for any help in advance.
|
|
|
In case any one would like to know I believe I have resolved my problem.
I basically took the strlen of buffer and copied each char except the last
one -- the new line. Result, the program now opens each file.
Btw, the compiler was g++, not gcc.
int main(){
// vars
char input[20];
char buffer[20];
char files[20];
string line;
string file;
int len; //new
vector<string> Data;
cout << "Input File : ";
cin >> input;
ifstream inputfile(input);
while (inputfile.getline(buffer,20)){ // should remove \n
len = strlen(buffer); //new
for (i=0;i <len-1; i++){
files = buffer;
}
ifstream datafile(files);
|
|
|
|
|
|
|
// |