It seems like ifstream*->open doesn't work as I expected...
Here is the code: ( compiled with g++ 4.7 using -std=c++11 in MAC OSX 10.7)
#include <string>
#include <iostream>
#include <fstream>
#include <vector>
using namespace std;
int main(int argc, char** argv)
{
string line;
vector<string> fname = {"a.txt","b.txt"};
vector<ifstream*> files ( 2, new ifstream );
files[0]->open( fname[0] );
getline( *files[0], line, '\n');
cerr<<"a.txt: "<<line<<endl;
//this one prints the first line of a.txt
line.clear();
files[1]->open( fname[1] );
getline( *files[1], line, '\n');
cerr<<"b.txt: "<<line<<endl;
//but this one fails to print any from b.txt
//actually, b.txt is not opened!
return 0;
}
Can any one tell me what is wrong here???
deleteon them, right?ifstream->openinstead ofifstream*->openwhich implies two de-references of the pointer (implied) byifstream? Asked instead of edited to get answer.