打开流的多个文本文件

mkuse

我想打开多个文本文件并将流存储为向量。

#include <vector>
#include <iostream>
#include <string>
#include <fstream>
using namespace std;

int main()
{

vector<string> imgSet
vector<ofstream> txtFiles;

// .
// .

    for( int i=0 ; i<imgSet.size() ; i++ )
    {
            ofstream s;
            s.open( imgSet[i].getName(), std::ofstream::out );
            txtFiles.push_back( s );
    }

}

getName看起来像:

const string& getName() const;

我正在ubuntu上使用G ++进行编译,我不明白为什么我会收到很多错误。如何解决

时髦猫

C ++ 03中的std :: fstream中没有operator =或copy构造函数。你可以这样做:

vector<ofstream*> txtFiles;
//...
for( int i=0 ; i<imgSet.size() ; i++ )
{
        txtFiles.push_back( new ofstream(imgSet[i].getName(), std::ofstream::out) );
}

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章