似乎不像ifstream*->open
我预期的那样工作......这是代码:(g++ 4.7
使用-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;
}
谁能告诉我这里出了什么问题???