ofstream*的向量不能打开任何元素
vector of ofstream* cannot open any element
在我的项目中,我试图创建一组用于输出的文件。然而,每当我试图接近这个时,我都无法打开任何流。我最好的方法是使用如下所示的ofstream指针向量,但我无法打开它们中的任何一个。
vector<ofstream*> out;
for (int m = 0; m < p; m++)
{
for (int n = 0; n < p; n++)
{
string outname = "TLR" + to_string(n) + "|" + to_string(m) + ".txt";
out.push_back(new ofstream{ outname.c_str() });
}
}
p通常为5。Is_open()显示没有打开(废话)。我的程序编译并运行时没有输出。Perror说"无效论证"。我使用的是运行windows 10的visual studio 2013。我该怎么做才能让它发挥作用呢?谢谢。
在Windows下,文件名中不允许使用|
字符。不允许使用?
、:
、<
、>
、、
/
、*
、"
等字符。
所以我不认为你不想创建一个ofstream对象的向量。相反,你要做的是为文件名创建一个字符串向量,并使用一个ofstream对象写入每个字符串。我想象的是这样的:
vector<string> out;
for (int m = 0; m < p; m++)
for (int n = 0; n < p; n++)
out.push_back("TLR" + to_string(n) + "_" + to_string(m)+ ".txt");
// Then iterate over the files writing to each one whatever you'd like with the ofstream
另外,就像人们在上面评论的那样,"|"字符是保留的,不能在文件名
相关文章:
- 如果第一个元素包含任何零,则我的程序以不希望的方式运行
- 是否有任何优雅的方式来遍历元素位置可以更改的列表?
- 查找字符串是否包含字符串向量的任何一个元素的最佳方法
- 循环,直到没有遇到 std::vector 的任何元素
- stl 中是否有任何数据结构可以在 O(1) 或 O(log n) 中插入元素,我可以在其上编写自己的bin_searc
- 从数组中删除元素,而无需在 c++ 中内置任何函数
- 任何更快地生成元素并检查它们是否为素数的方法
- 是否有任何方法可以比较C 中的STD ::的两个连续元素
- 在C 中弹出任何元素后,会自动调整数组大小
- 任何表示具有有序元素的对的 stl/boost 类型
- c ++中是否有任何方法可以在随机访问的列表中获取元素
- 删除数组中等于任何给定 targert 的元素
- 删除绑定到成员函数的 vector<std::function<...>> 的任何元素
- 容器具有恒定的时间,用于访问任何元素,从前面弹出并向后推
- 检查Eigen::矩阵的任何元素是否与零不同
- 带有移除任何元素方法的c++堆
- 向量错误抛掷分配经验甚至不访问任何元素
- 如何编写可以访问向量<Vec2s>内 Vec2s 任何元素的函数
- ofstream*的向量不能打开任何元素
- 如何使从函数返回的数字用于定义数组中的任何元素